Laravel - 在特定队列上重试失败的作业

Rob*_*Rob 2 laravel laravel-queue

我知道我可以重试 Laravel 应用程序中失败的作业,方法是使用:php artisan queue:retry 5ORphp artisan queue:retry all将它们推回到队列中。

我想实现的是只重试单个队列中失败的作业。比如php artisan queue:retry all --queue=emails哪个不行。

然而,我可以通过 ID 手动检查每个,php artisan queue:retry 5但是如果我有 1000 条记录,这无济于事。

总而言之,我的问题是,如何重试特定队列上的所有失败作业?

Zer*_*One 6

也许你可以创建另一个命令

让我们说

命令 : php artisan example:retry_queue emails

class RetryQueue extends Command
{
    protected $signature = 'example:retry_queue {queue_name?}';
    protected $description = 'Retry Queue';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
       // if the optional argument is set, then find all with match the queue name
       if ($this->argument('queue_name')) { 
            $queueList = FailedJobs::where('queue', $this->argument('queue_name'))->get();

            foreach($queueList as $list) {
                 Artisan::call('queue:retry '.$list->id);
            }
       } else {
            Artisan::call('queue:retry all');
       }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 我收到命令“queue:retry 6706”不存在。我想调用类似 Artisan::call('queue:retry', ['id' => $list->id]); 的命令 会解决这个问题。 (2认同)