如何在延迟作业队列中指定一名工作人员

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,所以我们使用的是一个 procfile,它将 运行 我们的工人:

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

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 文档,您会在末尾找到 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

Delayed Job 使用类似于 Resque 的东西。它使用环境变量 QUEUE 或 QUEUES 来指定特定工作人员的队列。

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

上验证