How to Specify One Worker on a Queue for Delayed Jobs

对着背影说爱祢 提交于 2021-02-07 19:29:26

问题


How can I specify one worker for a specific queue when using delayed jobs? I know I can run this command:

# Use the --pool option to specify a worker pool. You can use this option 
# multiple times to start different numbers of workers for different queues.
# The following command will start 1 worker for the tracking queue, 
# 2 workers for the mailers and tasks queues, and 2 workers for any jobs:

RAILS_ENV=production script/delayed_job --pool=tracking --pool=mailers,tasks:2 --pool=*:2 start

But since we are using heroku we are using a procfile that will run our workers:

worker: bundle exec foreman start -f Procfile.workers and our worker file runs the jobs:

worker_1: bundle exec rake jobs:work
worker_2: bundle exec rake jobs:work

What I am wanting to do however, is something like:

bundle exec rake jobs:work --queue=specific_queue

and only have one worker working on the specific_queue and other workers working on other queues.

How can I accomplish this?


回答1:


If you take a look at Heroku's Process Types and the Procfile docs, you will find this example at the end:

For example, using Ruby you could run two types of queue workers, each consuming different queues:

worker:        env QUEUE=* bundle exec rake resque:work
urgentworker:  env QUEUE=urgent bundle exec rake resque:work

Delayed Job uses something similar to Resque. It uses the env variables QUEUE or QUEUES to specify the queue for that particular worker.

You can verify that on lib/delayed/tasks.rb source code.



来源:https://stackoverflow.com/questions/39922669/how-to-specify-one-worker-on-a-queue-for-delayed-jobs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!