Alexander Nikolov
Alexander Nikolov

Reputation: 1979

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?

Upvotes: 1

Views: 929

Answers (1)

peterm
peterm

Reputation: 92785

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.

Upvotes: 2

Related Questions