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?
DEV3 Developer Forum
Why does my queue worker still run old code after I deploy?
Every post is reviewed first. Usually reviewed within 24 hours.
1 reply
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 thefiledriver 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:cacheruns in the deploy script before restarting workers, so they pick up new env values. Never callenv()outside config files once config is cached.- Set
retry_afterinconfig/queue.phplarger than your longest job timeout or the job runs twice. - Use
$tries,$backoffand afailed()method on the job for sensible retry behaviour.