Skip to content

Commit 5b6e5dd

Browse files
authored
Requeueing should not select failed batches (#698)
* test(qs): requeueing should not select failed batches * fix(qs): requeueing should not select failed batches * doc: add CHANGELOG
1 parent ba3865a commit 5b6e5dd

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# api
22

3+
## 8x.28.10 - 29 November 2023
4+
- Requeueing should not select failed batches
35

46
## 8x.28.9 - 28 November 2023
57
- Fix error reporting on detecting failed Qs Batches

app/Jobs/RequeuePendingQsBatchesJob.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ private function markBatchesFailed(): array
3737
->get()
3838
->pluck('id')
3939
->toArray();
40-
QsBatch::whereIn('id', $failedBatches)->update(['failed' => true]);
40+
QsBatch::whereIn('id', $failedBatches)->update([
41+
'failed' => true,
42+
'pending_since' => null,
43+
]);
4144
return $failedBatches;
4245
});
4346
}
@@ -48,10 +51,11 @@ private function requeueStalledBatches(): void
4851
QsBatch::where([
4952
['pending_since', '<>', null],
5053
['pending_since', '<', $threshold],
54+
['failed', '=', false],
5155
])
5256
->increment(
5357
'processing_attempts', 1,
54-
['pending_since' => null, 'done' => 0]
58+
['pending_since' => null, 'done' => false]
5559
);
5660
}
5761
}

tests/Jobs/RequeuePendingQsBatchesJobTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function testRequeue (): void {
3030
QsBatch::factory()->create(['pending_since' => Carbon::now()->subSeconds(200), 'id' => 1, 'done' => 0, 'wiki_id' => 1, 'entityIds' => 'a,b']);
3131
QsBatch::factory()->create(['pending_since' => Carbon::now()->subSeconds(400), 'id' => 2, 'done' => 0, 'wiki_id' => 1, 'entityIds' => 'a,b']);
3232
QsBatch::factory()->create(['processing_attempts' => 3, 'id' => 3, 'done' => 0, 'wiki_id' => 1, 'entityIds' => 'a,b']);
33+
QsBatch::factory()->create(['failed' => 1, 'processing_attempts' => 4, 'id' => 4, 'done' => 0, 'wiki_id' => 1, 'entityIds' => 'a,b']);
3334

3435
$mockExceptionHandler = $this->createMock(ExceptionHandler::class);
3536
$mockExceptionHandler
@@ -44,8 +45,10 @@ public function testRequeue (): void {
4445
->method('fail');
4546
$job->handle();
4647

47-
$this->assertEquals(QsBatch::where('pending_since', '=', null)->count(), 2);
48-
$this->assertEquals(QsBatch::where('failed', '=', true)->count(), 1);
48+
$this->assertEquals(QsBatch::where('pending_since', '=', null)->count(), 3);
49+
$this->assertEquals(QsBatch::where('failed', '=', true)->count(), 2);
4950
$this->assertEquals(QsBatch::where('id', '=', 2)->first()->processing_attempts, 1);
51+
$this->assertEquals(QsBatch::where('id', '=', 4)->first()->processing_attempts, 4);
52+
$this->assertEquals(QsBatch::where('id', '=', 4)->first()->pending_since, null);
5053
}
5154
}

0 commit comments

Comments
 (0)