繁体   English   中英

如何在队列中为延迟作业指定一个工作程序

[英]How to Specify One Worker on a Queue for Delayed Jobs

使用延迟作业时,如何为特定队列指定一个工作线程? 我知道我可以运行这个命令:

# 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

但是因为我们正在使用heroku,所以我们使用的proc文件将运行我们的worker:

worker: bundle exec foreman start -f Procfile.workers和我们的worker文件运行作业:

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

然而,我想要做的是:

bundle exec rake jobs:work --queue=specific_queue

并且只有一个工作人员在specific_queue上工作,其他工作人员在其他队列上工作。

我怎么能做到这一点?

如果你看看Heroku的Process Types and the Procfile文档,你会在最后找到这个例子:

例如,使用Ruby,您可以运行两种类型的队列工作程序,每个队列工作程序使用不同的队列:

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

延迟作业使用类似于Resque的东西。 它使用env变量QUEUE或QUEUES来指定该特定worker的队列。

您可以在lib/delayed/tasks.rb 源代码上验证。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM