DEV3 Technologies home

DEV3 Developer Forum

Why does my queue worker still run old code after I deploy?

Laravel helpSolved0 views
dev3 ·

I fixed a bug in a job class and deployed, but failed jobs still show the old error and the old behaviour. If I restart the server it works. How should I handle workers on deploy in Laravel 12?

#laravel#queue#deployment

0

1 reply

dev3 · Accepted answer

php artisan queue:work boots the framework once and keeps it in memory. It does not reload code or config until the process restarts. (queue:listen reloads each job but is slower and rarely recommended.)

Fix: restart workers gracefully on every deploy

php artisan queue:restart

This sets a cache timestamp; each worker finishes its current job and then exits. Your process manager (Supervisor, systemd) starts a fresh process with the new code. Requirements:

  • A cache driver that all workers can read (not array). With the file driver the web and worker users must share the same path.
  • A supervisor entry with autorestart=true.
[program:laravel-worker]
command=php /var/www/app/artisan queue:work --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
numprocs=2
stopwaitsecs=3600

--max-time=3600 makes workers recycle themselves hourly, which also limits memory leaks.

Failed jobs

Jobs serialize the class name and properties when dispatched. If you rename or change the constructor, old payloads in the queue can fail. Either keep the old signature working for a while, or clear the queue. To retry failed ones after the fix:

php artisan queue:retry all
php artisan queue:failed

Also remember

  • php artisan config:cache runs in the deploy script before restarting workers, so they pick up new env values. Never call env() outside config files once config is cached.
  • Set retry_after in config/queue.php larger than your longest job timeout or the job runs twice.
  • Use $tries, $backoff and a failed() method on the job for sensible retry behaviour.
0

Your reply

Every post is reviewed by DEV3 before it appears. Usually reviewed within 24 hours.

Markdown supported. Use ``` for code blocks. Images are not allowed.