Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel queue worker with cron

I am trying to get my website to send confirmations emails every time someone new register.

i did it like following after reading about it, but i am still not convinced that this is the best way to do it.

in my cron runs every minute and calls php artisan schedule:run

in my console/Kernel

protected function schedule(Schedule $schedule)
{
    $schedule->command('queue:work --once')->everyMinute()->withoutOverlapping();
}

i added the --once parameter because the queue worker is not existing when finished, and i do not want to have many new processes running every minute.

is there a way to make the queue worker finish all the jobs and exit and then start it after one minute again so that i do not have many instances , or is it just one instance ??

i read that i can return null to exit the worker, but if this can be done, then how can i return null only after the last job is done?

like image 669
A. Dabak Avatar asked Sep 29 '17 11:09

A. Dabak


1 Answers

for any one still looking for a solution, in laravel 5.7 they added support to run all jobs in the queue and then stop the queue worker when all jobs are done.

Your cronjob should run this: php /path/to/laravel/artisan queue:work --stop-when-empty

Queue worker command source code on Github

plus there is a package available for older versions of laravel

orobogenius/sansdaemon

like image 185
A. Dabak Avatar answered Nov 04 '22 09:11

A. Dabak