Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create delays between failed Queued Job attempts in Laravel?

I have a queued job in Laravel that fails from time to time because of an external API failing due to high load. The problem is that my choices appear to be to have the Laravel Queue continue to hammer the API with requests until it succeeds or tell it to stop after X number of requests.

Is there any way for me to, based on how the job fails, tell it to try again in 5 minutes instead of continuing to hammer away?

I want to use the built in queue handler, but the retry functionality doesn't appear to be built to handle real life scenarios of failure. I would think that many reasons for failing a job wouldn't be solved by immediately trying again.

like image 646
Citizen Avatar asked Feb 07 '16 19:02

Citizen


People also ask

How do I retry failed jobs in Laravel?

You can even retry all jobs at once by executing the php artisan queue:retry --all command. Alternatively, if you want to retry failed jobs from a certain queue, you can execute the php artisan queue:retry --queue=high-priority command.

What is sync queue Laravel?

Sync, or synchronous, is the default queue driver which runs a queued job within your existing process. With this driver enabled, you effectively have no queue as the queued job runs immediately.

What is the difference between job and queue in Laravel?

Jobs and QueuesThe line itself is the Queue, and each customer in the line is a Job. In order to process Jobs in the Queue you need command line processes or daemons. Think of launching a queue daemon on the command line as adding a new bank teller to the pool of available bank tellers.


1 Answers

Laravel 8

/**
 * The number of seconds to wait before retrying the job.
 *
 * @var int
 */
public $backoff = 3;
like image 63
habib Avatar answered Sep 21 '22 18:09

habib