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

helpyousponsor's avatar

How to handle errors in beanstalkd queues

I'm implementing queues in an app and have noticed that if there is a bug in my code that the job doesn't fail and will just hang in the queue. For example, in refactoring my code I had an undeclared variable which threw a php error. The job just hung in the queue until I manually cleared all jobs out of the queue. I thought the job would just fail but it doesn't. Is there a way to handle something like this?

0 likes
4 replies
helpyousponsor's avatar

Nevermind. Sometimes it seems I have to post a problem before I realize the simple solution. For anyone else with a similar problem the solution was as simple as wrapping the job in a try/catch. In the catch I log the error and do a $job->delete() so that it doesn't sit there clogging up the queue.

Valorin's avatar
Valorin
Best Answer
Level 4

You can tell the queue worker how many failed attempts to try before it dumps it in a failed table and moves on. Check the Artisan commands :-)

1 like
helpyousponsor's avatar

Thanks Valorin. I mistakenly assumed that a failed job would be moved to the failed table but that is only after it has failed the determined number of times. And there is no default number of times a job can fail so without setting the tries it keeps trying.

RobMeijer's avatar

It really depends on the job. For some jobs, you may not want to lose the information held in the payload. In that case, you simply need to fix the error, and restart the worker so that the job can be processed correctly.

Please or to participate in this conversation.