Skip to content

Commit

Permalink
Do not allow pending_jobs < 0 + log if it happens
Browse files Browse the repository at this point in the history
  • Loading branch information
cyppe committed Feb 10, 2024
1 parent e8c9285 commit d7d36b0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Repositories/RedisBatchRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,15 @@ public function decrementPendingJobs( string $batchId, string $jobId )
return new UpdatedBatchJobCounts( 0, 0 );
}
$batchData = json_decode( $data, true );
$batchData['pending_jobs']--;

// Check if pending_jobs is greater than 0 before decrementing
if ($batchData['pending_jobs'] > 0) {
$batchData['pending_jobs']--;
} else {
// Will remove later - keeping for debug for now to see if it ever happens
Log::warning("Attempted to decrement pending_jobs below 0 for batch: " . $batchId);
}

Redis::set( "batch:$batchId", json_encode( $batchData ) );
return new UpdatedBatchJobCounts( $batchData['pending_jobs'], $batchData['failed_jobs'] );
}, 100, 200 );
Expand Down

0 comments on commit d7d36b0

Please sign in to comment.