Support the ongoing development of Laravel.io →
posted 5 years ago
Queues

I have a few issues. We do a lot of background work in a pool of several hundred artisan workers across numerous servers. Each job may execute for upwards of several hours, even though we're about as granular as you can get with tiny units of work. It's just time-consuming.

A few things I want to do. I probably need to write an artisan command that sets the queueing mechanism in "maintenance mode". This would tell all workers to stop what they are doing, release the job for future execution, and importantly to suppress any attempt to pick new jobs off the queue for any workers on other boxes.

We currently use the database driver for queues and caching, but we're switching to redis in the near future. As of now, if a worker dies, gets killed, throws a fatal exception, etc., the job remains "locked". No other worker will attempt to touch that dead job until the retry_after timeout expires. What I would like to have happen is that when using Redis, if the process that popped the queue job dies, it should immediately release the job for another worker to pick up eventually.

Am I correct in assuming that when using Redis, Laravel will automatically free the job if worker process dies a violent death? And is there an existing package that offers a mechanism to stop workers gracefully?

Last updated 3 years ago.
0

About your first question

I'm not sure actually, I suppose the job will fail and it will be retried after the retry_after timeout

About your second question

Laravel Horizon provides a way to gracefully terminate the worker processes

See https://laravel.com/docs/6.x/horizon

php artisan horizon:terminate will wait until your current jobs are processed and wont pick new ones after they are processed.

What you can probably with horizon is to minimize the retry_after configuration for a specific queue only, so if jobs fails in this queue it will be available as soon as possible for other workers.

Probably, I can't imagine the whole picture though, but I hope that helps a little

Last updated 5 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.