【问题标题】:Laravel - Retry failed jobs on a specific queueLaravel - 在特定队列上重试失败的作业
【发布时间】:2018-10-18 11:29:37
【问题描述】:

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

我想要实现的是只重试来自单个队列的失败作业。如php artisan queue:retry all --queue=emails 不起作用。

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

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

【问题讨论】:

    标签: laravel laravel-queue


    【解决方案1】:

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

    让我们说

    命令: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');
           }
        }
    }
    

    【讨论】:

    • 如果它在 Laravel 中尚不存在,那么这是实现它的好方法。谢谢。
    • 我得到命令“queue:retry 6706”不存在。我猜想像 Artisan::call('queue:retry', ['id' => $list->id]); 这样调用命令会解决的。
    • 由于某种原因,我无法在 Laravel 8 中访问 FailedJobs 模型,因此我使用了 DB 外观。例如 \DB::table('failed_jobs')..
    猜你喜欢
    • 2014-11-19
    • 2019-07-10
    • 2020-11-04
    • 1970-01-01
    • 2018-08-16
    • 2019-09-06
    • 2021-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多