在每个delay_job抽佣作业中获取额外的rufus-scheduler线程:工作 [英] Getting extra rufus-scheduler thread with each delayed_job rake jobs:work
问题描述
我正试图使用rufus-scheduler检查每一分钟,以查看是否 有准备好要放置在delay_job队列中的作业.
Am trying to use rufus-scheduler to check every minute or so to see if there are jobs ready to be placed in the delayed_job queue.
在#{RAILS_ROOT}/config/initializers中具有一个初始化脚本,该脚本可以 启动调度程序.不幸的是,耙工作:工作也运行 Rails初始化过程,因此每个都可以开始 工作:工作已经开始.
Have an initializer script in #{RAILS_ROOT}/config/initializers that starts the scheduler. Unfortunately the rake jobs:work also runs the rails initialization process so another gets started for each jobs:work started.
如何防止这种情况?
运行红宝石1.8.6.26,导轨2.3.5,dj 1.8.5,rufus-scheduler 2.0.6于 XP pro sp3
Running ruby 1.8.6.26, rails 2.3.5, dj 1.8.5, rufus-scheduler 2.0.6 on XP pro sp3
推荐答案
在初始化程序中,找到一种方法,如果通过Rake调用rails初始化过程,则不运行计划.
In your initializer, find a way not to run the schedule if the rails initialization process is invoked via Rake.
可以肯定的是,这是一种更加卑鄙的方式,但是您可以做到
For sure there is a more railsy way, but you could do
unless defined?(Rake)
# do the scheduling...
end
如果定义了恒定的Rake(对于Rake任务,则不定义),则不会调用执行调度"块.
The block 'do the scheduling' won't get called if the constant Rake is defined (for a Rake task it is defined).
这篇关于在每个delay_job抽佣作业中获取额外的rufus-scheduler线程:工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!