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

Commit

Permalink
Merge pull request #86 from cognitus/main
Browse files Browse the repository at this point in the history
Fix  | Do Not Delete Haystack On Failure
  • Loading branch information
Sammyjo20 authored May 14, 2024
2 parents 377dd6b + 1cd758a commit 10c07c6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
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

0 comments on commit 10c07c6

Please sign in to comment.