加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何在队列中为延迟作业指定一个worker

发布时间:2020-12-17 02:26:06 所属栏目:百科 来源:网络整理
导读:使用延迟作业时,如何为特定队列指定一个工作线程?我知道我可以运行这个命令: # 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
使用延迟作业时,如何为特定队列指定一个工作线程?我知道我可以运行这个命令:

# 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和Procfile文档,你会在最后找到 this的例子:

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

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

您可以在lib / delayed / tasks.rb source code上验证.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读