Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Fix | Do Not Delete Haystack On Failure #86

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Concerns/ManagesBales.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function finish(FinishStatus $status = FinishStatus::Success): void

// Now finally delete itself.

if (config('haystack.delete_finished_haystacks') === true) {
if ($status === FinishStatus::Success && config('haystack.delete_finished_haystacks') === true) {
$this->delete();
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Feature/HaystackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Carbon;

use function Pest\Laravel\assertModelExists;
use function Pest\Laravel\travel;

use Illuminate\Support\Collection;
Expand Down Expand Up @@ -439,7 +440,7 @@

expect(cache()->get('failed'))->toBeTrue();

assertModelMissing($haystack);
assertModelExists($haystack); // Should still exist
});

test('the haystack will fail if the job is manually failed', function () {
Expand All @@ -458,7 +459,7 @@

expect(cache()->get('failed'))->toBeTrue();

assertModelMissing($haystack);
assertModelExists($haystack); // Should still exist
});

test('a haystack can be cancelled early and future jobs wont be processed', function () {
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/HaystackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function myFunction()
expect(Haystack::all())->toHaveCount(0);
});

test('when a haystack fails it will delete itself and all bales', function () {
test('when a haystack fails it will remain with the final bales', function () {
$haystack = Haystack::factory()
->has(HaystackBale::factory()->state(['job' => new NameJob('Sam')]), 'bales')
->create();
Expand All @@ -186,8 +186,8 @@ function myFunction()

$haystack->fail();

expect(Haystack::all())->toHaveCount(0);
expect(HaystackBale::all())->toHaveCount(0);
expect(Haystack::all())->toHaveCount(1);
expect(HaystackBale::all())->toHaveCount(1);
});

test('you can instantiate a haystack builder from the model', function () {
Expand Down
Loading