Reputation: 6020
How can I check if a job fails to finish?
And how can I tell the job to retry inside job's handle function?
Or how can I force a job to be considered as a failed job?
Upvotes: 3
Views: 7910
Reputation: 494
And how can I tell the job to retry inside job's handle function?
Not sure if applicable to other connection types but if you are using Redis, job can be released back to the queue right from the handle() body by command:
$this->release(10);
Where 10 is delay in seconds, after which it should be returned back to the queue.
Upvotes: 1
Reputation: 28554
You can implement the failed function in your Job.
<?php
namespace App\Jobs;
.......
public function failed(\Exception $exception)
{
\Log::info('job failed');
}
}
Upvotes: 1
Reputation: 6020
I figured out that the code needs to fail to run (or throw an exception) to be considered as failed job.
I just put a throw new Exception()
where I needed.
Then laravel behaves it as a failed job.
Upvotes: 3