Skip to content

Commit 3a81750

Browse files
authored
fix(qs): batches that are done shall never be marked failed (#707)
* fix(qs): batches that are done shall never be marked failed * docs: add changelog * fix: whitespace was missing from error message * fix: failed and processing_attempts are not fillable
1 parent 5b6e5dd commit 3a81750

4 files changed

Lines changed: 10 additions & 2 deletions

File tree

CHANGELOG.md

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

3+
## 8x.28.11 - 12 December 2023
4+
- Batches that are done shall never be marked failed
5+
36
## 8x.28.10 - 29 November 2023
47
- Requeueing should not select failed batches
58

app/Jobs/RequeuePendingQsBatchesJob.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function handle(): void
2020
{
2121
$failedBatches = $this->markBatchesFailed();
2222
foreach ($failedBatches as $batchId) {
23-
report("QsBatch with ID ".$batchId."was marked as failed.");
23+
report("QsBatch with ID ".$batchId." was marked as failed.");
2424
}
2525

2626
$this->requeueStalledBatches();
@@ -32,6 +32,7 @@ private function markBatchesFailed(): array
3232
$failedBatches = QsBatch::where([
3333
['processing_attempts', '>=', $this->markFailedAfter],
3434
['failed', '=', false],
35+
['done', '=', false]
3536
])
3637
->select('id')
3738
->get()

app/QsBatch.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class QsBatch extends Model
3737
'wiki_id',
3838
'entityIds',
3939
'pending_since',
40+
'failed',
41+
'processing_attempts',
4042
];
4143

4244
protected $casts = [

tests/Jobs/RequeuePendingQsBatchesJobTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function testRequeue (): void {
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']);
3333
QsBatch::factory()->create(['failed' => 1, 'processing_attempts' => 4, 'id' => 4, 'done' => 0, 'wiki_id' => 1, 'entityIds' => 'a,b']);
34+
QsBatch::factory()->create(['failed' => 0, 'processing_attempts' => 3, 'id' => 5, 'done' => 1, 'wiki_id' => 1, 'entityIds' => 'a,b']);
3435

3536
$mockExceptionHandler = $this->createMock(ExceptionHandler::class);
3637
$mockExceptionHandler
@@ -45,10 +46,11 @@ public function testRequeue (): void {
4546
->method('fail');
4647
$job->handle();
4748

48-
$this->assertEquals(QsBatch::where('pending_since', '=', null)->count(), 3);
49+
$this->assertEquals(QsBatch::where('pending_since', '=', null)->count(), 4);
4950
$this->assertEquals(QsBatch::where('failed', '=', true)->count(), 2);
5051
$this->assertEquals(QsBatch::where('id', '=', 2)->first()->processing_attempts, 1);
5152
$this->assertEquals(QsBatch::where('id', '=', 4)->first()->processing_attempts, 4);
5253
$this->assertEquals(QsBatch::where('id', '=', 4)->first()->pending_since, null);
54+
$this->assertEquals(QsBatch::where('id', '=', 5)->first()->failed, 0);
5355
}
5456
}

0 commit comments

Comments
 (0)