简体   繁体   中英

Laravel 4.2 Queue - force job fail

I want to do something like this in my fire method:

class MyClass{
    public function fire($job) {
       if(something) {
          $job->fail();
       }else {
        //processing
       }
       $job->delete();
}

There is no such method as fail(), is it possible to do something like this?

There is no such thing as fail a job but what you can do:

  1. release it back to the queue with

     $job->release(); 

After defined number of attempts it will end up in failed jobs table.

  1. throw an exception. The job will be released back to the queue on it's own.

  2. if you're using beanstalkd as a queue driver you can bury a job

     $job->bury(); 
  3. If your condition is unrecoverable you can log this fact and simply delete the job.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM