Skip to content

Commit

Permalink
Prevent infinite loop when forgetting failed jobs (#1429)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwh authored Apr 25, 2024
1 parent 0f08459 commit c918b06
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Console/ForgetFailedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ public function handle(JobRepository $repository)
$totalFailedCount = $repository->totalFailed();

do {
collect($repository->getFailed())->pluck('id')->each(function ($failedId) use ($repository): void {
$failedJobs = collect($repository->getFailed());

$failedJobs->pluck('id')->each(function ($failedId) use ($repository): void {
$repository->deleteFailed($failedId);

if ($this->laravel['queue.failer']->forget($failedId)) {
$this->components->info('Failed job (id): '.$failedId.' deleted successfully!');
}
});
} while ($repository->totalFailed() !== 0);
} while ($repository->totalFailed() !== 0 && $failedJobs->isNotEmpty());

if ($totalFailedCount) {
$this->components->info($totalFailedCount.' failed jobs deleted successfully!');
Expand Down

0 comments on commit c918b06

Please sign in to comment.