I am using a laravel queue job to send emails with an excel attachment. And many a time it is happening, that whenever I update any code change, it doesn't consider the updated code, rather it runs the old code. How can I prevent this?
Asked
Active
Viewed 9,474 times
12

Marcin Nabiałek
- 109,655
- 42
- 258
- 291

Nitish Patra
- 289
- 5
- 20
-
2Restart the queue worker and it should be fine. – thisiskelvin Oct 22 '18 at 13:04
-
stop queue and again start after update code – Jignesh Joisar Oct 22 '18 at 13:05
-
1Did that too, did a clear-compiled, restarted supervisor, cleared cache, views and all. But still it persists – Nitish Patra Oct 22 '18 at 13:05
-
run php artisan queue:restart – Jacob Oct 22 '18 at 13:08
-
Tried that too Jacob – Nitish Patra Oct 22 '18 at 13:11
-
If you changed something in the settings or the .env file, you have to run `config:cache` as well. Depending on your server setup, you may have to actually kill the `queue:work` process instead of restart it. – Dimitri Mostrey Oct 22 '18 at 13:32
-
@dimitri Is the config: cache essential. Usually, I go for clearing that. Also, the queue work is maintained by the Supervisor, which automatically starts or restarts the queue. Is it required to do so from my end? – Nitish Patra Oct 22 '18 at 16:17
-
Possible duplicate of [laravel 5.1 not seeing changes to Job file without VM restart](https://stackoverflow.com/questions/30881324/laravel-5-1-not-seeing-changes-to-job-file-without-vm-restart) – ceejayoz Oct 22 '18 at 18:21
-
Thanks, everyone for the suggestion. My issue is resolved now. It was actually throwing up an exception, which was not being handled. I manually logged the exception and got the issue fixed. And now it is running fine. I guess if the supervisor is taking care of queue restart, manually queue: restart do help, I am not sure though, but it seems to be helpful. – Nitish Patra Oct 23 '18 at 05:12
1 Answers
34
Each time you deploy your Laravel app, or make any code change, you should run:
php artisan queue:restart
Of course make sure that in Supervisor you have set autostart
to true.
You can read on https://laravel.com/docs/5.4/queues#running-the-queue-worker :
Since queue workers are long-lived processes, they will not pick up changes to your code without being restarted. So, the simplest way to deploy an application using queue workers is to restart the workers during your deployment process. You may gracefully restart all of the workers by issuing the queue:restart

Toby Allen
- 10,997
- 11
- 73
- 124

Marcin Nabiałek
- 109,655
- 42
- 258
- 291
-
1This does not work if you use Laravel Envyoer and Forge. Tried many ways, and its impossible to restart without actually killing supervisor processors entirely. Wish there was another way. – tmarois Apr 23 '22 at 16:48