如何防止排队作业在失败后执行



我已经配置了我的主管工作人员,以便在失败的情况下尝试 3 次 laravel排队作业。下面是我的工作线程配置示例。

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php home/vagrant/Code/lead_reactor/artisan queue:work database --sleep=3 --tries=3 --daemon
autostart=true
autorestart=true
user=vagrant
numprocs=8
redirect_stderr=true
stdout_logfile=home/vagrant/Code/lead_reactor/storage/logs/laravel-worker.log

但我确实有一个特定的 laravel 作业队列,无论是否失败,我只想执行一次。我想在不更改我的工作配置的情况下,防止将来尝试在失败时执行作业。

以下是我的工作类的结构。

class SendBugReports extends Job implements SelfHandling, ShouldQueue
{
    use InteractsWithQueue, SerializesModels;
    protected $bugReports;
    /**
     * Create a new job instance.
     *
     */
    public function __construct()
    {
        $this->bugReports = BugReport::all();
    }
    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //job processes...
    }
}

任何帮助将不胜感激! :)

您可以使用尝试方法检查运行作业的尝试次数:

public function handle()
{
    if ($this->attempts() > 1) {
        return;
    }
}