Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bearbytestudio's avatar

How to best handle jobs which will take 5 minutes or longer to complete

I have a few jobs in my app which are dispatched onto a queue (we use Horizon to run our queues), and can take anywhere up to 10 minutes to complete their work. For reasons I cannot pin down, seemingly when no errors happen, I get the jobs rerunning and re-dispatching onto the queue even when one is in progress already. The only logs in my log file are saying "MaxAttemptsExceededException".

Here is my job:

Here is my horizon config:

Any pointers hugely appreciated!

0 likes
2 replies
Glukinho's avatar

A job is returned to queue in these cases:

  1. exception was thrown during execution
  2. job worked longer than $timeout or worker's --timeout (job class specified $timeout takes precedence, according to docs)
  3. $this->release($seconds) was called inside a job.

Try to investigate which case is yours.

After job is back in queue, it will or will not be run again based on job class's $tries, retryUntil() { ... }, $maxExceptions or worker's --tries values.

I would set all tries and retryUntil values to something high and see if jobs go back to queue and why.

1 like
bearbytestudio's avatar

Thanks v much, appreciate the tips. I'll try out a few of those suggestions and hopefully get to the bottom of it. Will update here if I do!

Please or to participate in this conversation.