Laravel Artisan CLI safely stop daemon queue workers

前端 未结 4 2198
刺人心
刺人心 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条回答
  •  借酒劲吻你
    2021-01-01 18:36

    We've implemented something like this in our application - but it was not something that was built-in to Laravel itself. You would have to edit this file, by adding another condition to the if-block so that it would call the stop function. You can do this by either setting a static variable in the Worker class that gets changed whenever you run a custom command that you'll have to make (i.e. php artisan queue:pause) or by checking an atomic value somewhere (i.e. set it in some cache like redis, memcached, APC or even MySQL, though this would mean you'll have one MySQL query for every cycle of this while-loop) that you set using the same custom command.

提交回复
热议问题