laravelqueuelaravel-queuelaravel-jobs

is queue:restart laravel command necessary?


i implemented laravel queue in shared hosting by this steps:

1- I set this CronJob on the host for every minute:

* * * * * /usr/local/bin/php /home1/myuser/myfolder/artisan schedule:run >> /dev/null 2>&1

2- I set this command on kernel.php:

$schedule->command('queue:work --daemon')->withoutOverlapping();

and my queued jobs are working well

my question is: is it necessary to use queue:restart laravel command for "die" queues after they finish?


Solution

  • You do not have to kill queues after they finished (what is finished?). The queue worker runs all the jobs automatically. You do not even need a scheduler for that. Just run php artisan queue:work --daemon and everything happens automatically.

    I think the critical point is when you update your laravel app or the queue worker stops for some reason (crashes).

    About the updates: php artisan queue:work --daemon uses the instance of your app from when it was started, like php artisan tinker does aswell. If you don't stop your queue before updating, you usually end with many queue processes on your system, because the app will start new ones after updates. I'm not sure if these processes do any damage, but I would stop the queues. I would also encourage you to read https://laravel.com/docs/7.x/scheduling.

    About the crash: At our company we are using a service that ensures that the php artisan queue:work process is running. Advantage here is that we can stop the service while updating.

    Please correct me if i am wrong. I started the same way as the OP and this is were I am now :)