Skip to content

Commit

Permalink
Enhance forget command (#1409)
Browse files Browse the repository at this point in the history
* Enhance forget command

* Update ForgetFailedCommand.php

* Update ForgetFailedCommand.php

* Update ForgetFailedCommand.php

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
jaroslavstefanec and taylorotwell committed Apr 4, 2024
1 parent ffdb4b8 commit 8a34309
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/Console/ForgetFailedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ForgetFailedCommand extends Command
*
* @var string
*/
protected $signature = 'horizon:forget {id : The ID of the failed job}';
protected $signature = 'horizon:forget {id? : The ID of the failed job} {--all : Delete all failed jobs}';

/**
* The console command description.
Expand All @@ -30,6 +30,32 @@ class ForgetFailedCommand extends Command
*/
public function handle(JobRepository $repository)
{
if ($this->option('all')) {
$totalFailedCount = $repository->totalFailed();

do {
collect($repository->getFailed())->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);

if ($totalFailedCount) {
$this->components->info($totalFailedCount.' failed jobs deleted successfully!');
} else {
$this->components->info('No failed jobs detected.');
}

return;
}

if (! $this->argument('id')) {
$this->components->error('No failed job ID provided.');
}

$repository->deleteFailed($this->argument('id'));

if ($this->laravel['queue.failer']->forget($this->argument('id'))) {
Expand Down

0 comments on commit 8a34309

Please sign in to comment.