如何将工作人员分成有延迟工作+ heroku的工作岗位? [英] How do I separate workers into pools of jobs with delayed job + heroku?
问题描述
我有一个max我需要专门为3名工作人员每小时产生一组优先任务,大约需要26分钟才能完成。在此期间,不太重要的后台任务需要继续,可能有1名工作人员专门负责这些任务。
因此,我会将该块优先级任务设置为名为队列,例如'hourtask',然后为其他所有'everythingelse'命名为队列:)
现在的问题是,我如何将heroku工作者分配给特定的队列?根据文档,这与环境变量有关吗?它说:
#将--queue或--queues选项设置为从特定队列工作。
$ RAILS_ENV =生产脚本/ delayed_job --queue =跟踪开始
$ RAILS_ENV =生产脚本/ delayed_job --queues =邮寄者,任务开始
但是我对使用heroku设置不熟悉如何将其应用于我的heroku生产环境?
它在延迟作业3的自述文件中:
DJ 3引入了Resque风格的命名队列,同时仍保留DJ风格的优先级。我们的目标是提供一个系统,用于对不同工作人员的工作池进行分组任务,这些工作人员可以分别进行缩放和控制。
工作可以分配到一个队列设置队列选项:
object.delay(:queue =>'tracking')。method
Delayed :: Job.enqueue作业,:队列=> 'tracking'
handle_asynchronously:tweet_later,:queue => 'tweets'
脚本/ delayed_job可用于管理后台进程,该进程将开始关闭作业。
为此,请将gemdaemons添加到Gemfile中,并确保已经运行 rails generate delayed_job
。
您可以执行以下操作:
$ RAILS_ENV =生产脚本/ delayed_job start
$通过设置QUEUE或QUEUES环境变量消除队列。
$ RAILS_ENV =生产脚本/ delayed_job stop
#在单独的进程中运行两个工人。
$ RAILS_ENV =生产脚本/ delayed_job -n 2开始
$ RAILS_ENV =生产脚本/ delayed_job stop
#设置--queue或--queues选项从a特定队列。
$ RAILS_ENV =生产脚本/ delayed_job --queue =跟踪开始
$ RAILS_ENV =生产脚本/ delayed_job --queues =邮寄者,任务开始
QUEUE =追踪佣金工作:工作
QUEUES =寄件人,任务佣金工作:工作
在Heroku中,在你的proc文件中,创建两个条目:
$ p $worker1:QUEUE =跟踪耙子作业:工作
worker2: QUEUES =邮寄者,任务佣金工作:工作
并逐个缩放它们:
heroku ps:scale worker1 = 2 worker2 = 1
etc
My environment is rails 3.1, heroku bamboo stack, delayed_job_active_record, (https://github.com/collectiveidea/delayed_job ) and experimenting with hirefire. (https://github.com/meskyanichi/hirefire) - I can see the delayed_job queue documentation, but how do I apply this on heroku?
I have a max priority set of tasks that get spawned off every hour that I need to dedicate 3 workers to, it takes approx 26 minutes to complete. During that time, less important background tasks need to continue, with perhaps 1 worker dedicated to them.
So I'll set that block of priority tasks to being in a named queue, e.g. 'hourtask', and then name a queue for everything else 'everythingelse' :)
The question is, how do I dedicate heroku workers to specific queues? Is it something to do with the environment variables as per the documentation? It says:
# Set the --queue or --queues option to work from a particular queue.
$ RAILS_ENV=production script/delayed_job --queue=tracking start
$ RAILS_ENV=production script/delayed_job --queues=mailers,tasks start
But I'm not familiar enough with heroku setup to work out how to apply this to my heroku production environment?
It's in the README for Delayed Job 3:
DJ 3 introduces Resque-style named queues while still retaining DJ-style priority. The goal is to provide a system for grouping tasks to be worked by separate pools of workers, which may be scaled and controlled individually.
Jobs can be assigned to a queue by setting the queue option:
object.delay(:queue => 'tracking').method
Delayed::Job.enqueue job, :queue => 'tracking'
handle_asynchronously :tweet_later, :queue => 'tweets'
script/delayed_job can be used to manage a background process which will start working off jobs.
To do so, add gem "daemons" to your Gemfile and make sure you’ve run rails generate delayed_job
.
You can then do the following:
$ RAILS_ENV=production script/delayed_job start
$ RAILS_ENV=production script/delayed_job stop
# Runs two workers in separate processes.
$ RAILS_ENV=production script/delayed_job -n 2 start
$ RAILS_ENV=production script/delayed_job stop
# Set the --queue or --queues option to work from a particular queue.
$ RAILS_ENV=production script/delayed_job --queue=tracking start
$ RAILS_ENV=production script/delayed_job --queues=mailers,tasks start
Work off queues by setting the QUEUE or QUEUES environment variable.
QUEUE=tracking rake jobs:work
QUEUES=mailers,tasks rake jobs:work
On Heroku, In your procfile, create two entries:
worker1: QUEUE=tracking rake jobs:work
worker2: QUEUES=mailers,tasks rake jobs:work
and scale them individually:
heroku ps:scale worker1=2 worker2=1
etc
这篇关于如何将工作人员分成有延迟工作+ heroku的工作岗位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!