Skip to content

Commit d7d36b0

Browse files
committed
Do not allow pending_jobs < 0 + log if it happens
1 parent e8c9285 commit d7d36b0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Repositories/RedisBatchRepository.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,15 @@ public function decrementPendingJobs( string $batchId, string $jobId )
186186
return new UpdatedBatchJobCounts( 0, 0 );
187187
}
188188
$batchData = json_decode( $data, true );
189-
$batchData['pending_jobs']--;
189+
190+
// Check if pending_jobs is greater than 0 before decrementing
191+
if ($batchData['pending_jobs'] > 0) {
192+
$batchData['pending_jobs']--;
193+
} else {
194+
// Will remove later - keeping for debug for now to see if it ever happens
195+
Log::warning("Attempted to decrement pending_jobs below 0 for batch: " . $batchId);
196+
}
197+
190198
Redis::set( "batch:$batchId", json_encode( $batchData ) );
191199
return new UpdatedBatchJobCounts( $batchData['pending_jobs'], $batchData['failed_jobs'] );
192200
}, 100, 200 );

0 commit comments

Comments
 (0)