Skip to content

Enhance forget command #1409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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