Laravel Artisan CLI safely stop daemon queue workers

前端 未结 4 2217
刺人心
刺人心 2021-01-01 18:03

In order to process large numbers of jobs, I run a variable number of queue workers depending on howmuch work there is to complete. I don\'t want to run more workers than ar

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-01 18:32

    Since Laravel 5.5 there is an event called Illuminate\Queue\Events\Looping that gets fired from the daemonShouldRun() call inside the main worker loop of Illuminate\Queue\Worker. So if you setup a listener to do your should process jobs check, and return false then the queue worker(s) will stop until the check returns true. There's a sleep between the next time it checks it which you can customise by passing --sleep to the queue:work command.

    I'm currently using this technique during deployments to stop workers which run inside docker containers, as it's not so easy to run the suggested queue:restart on them without hacking around.

提交回复
热议问题