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

Commit 10c07c6

Browse files
authored
Merge pull request #86 from cognitus/main
Fix | Do Not Delete Haystack On Failure
2 parents 377dd6b + 1cd758a commit 10c07c6

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/Concerns/ManagesBales.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function finish(FinishStatus $status = FinishStatus::Success): void
201201

202202
// Now finally delete itself.
203203

204-
if (config('haystack.delete_finished_haystacks') === true) {
204+
if ($status === FinishStatus::Success && config('haystack.delete_finished_haystacks') === true) {
205205
$this->delete();
206206
}
207207
}

tests/Feature/HaystackTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Carbon;
66

7+
use function Pest\Laravel\assertModelExists;
78
use function Pest\Laravel\travel;
89

910
use Illuminate\Support\Collection;
@@ -439,7 +440,7 @@
439440

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

442-
assertModelMissing($haystack);
443+
assertModelExists($haystack); // Should still exist
443444
});
444445

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

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

461-
assertModelMissing($haystack);
462+
assertModelExists($haystack); // Should still exist
462463
});
463464

464465
test('a haystack can be cancelled early and future jobs wont be processed', function () {

tests/Unit/HaystackTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function myFunction()
176176
expect(Haystack::all())->toHaveCount(0);
177177
});
178178

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

187187
$haystack->fail();
188188

189-
expect(Haystack::all())->toHaveCount(0);
190-
expect(HaystackBale::all())->toHaveCount(0);
189+
expect(Haystack::all())->toHaveCount(1);
190+
expect(HaystackBale::all())->toHaveCount(1);
191191
});
192192

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

0 commit comments

Comments
 (0)