mardi 17 janvier 2017

How To Prevent Queued Job From Executing After Failure?

I have configured my supervisor worker to attempt laravel queued job 3 times in case of failure. Below is the sample of my worker config.

[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

But I do have a specific laravel job queue that I want to be executed only once regardless if there is a failure or none. I want to prevent the future attempts of job execution if there is failure without changing my worker config.

Below is the structure of my job class.

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...
    }
}

Any help will greatly appreciated! :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire