master

laravel/framework

Last updated at: 29/12/2023 09:24

ForgetFailedCommand.php

TLDR

The ForgetFailedCommand class in the file ForgetFailedCommand.php is a command that can be run from the console to delete a failed queue job. It is part of the Illuminate\Queue\Console namespace and extends the Command class.

Methods

handle

The handle method is responsible for executing the console command. It retrieves the ID of the failed job as an argument and uses the queue.failer service to delete the job. If the job is successfully deleted, it displays a success message using the info method of the components property. If no failed job matches the given ID, it displays an error message using the error method of the components property.

Classes

There are no additional classes in this file.

<?php

namespace Illuminate\Queue\Console;

use Illuminate\Console\Command;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'queue:forget')]
class ForgetFailedCommand extends Command
{
    /**
     * The console command signature.
     *
     * @var string
     */
    protected $signature = 'queue:forget {id : The ID of the failed job}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Delete a failed queue job';

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        if ($this->laravel['queue.failer']->forget($this->argument('id'))) {
            $this->components->info('Failed job deleted successfully.');
        } else {
            $this->components->error('No failed job matches the given ID.');
        }
    }
}