scheduler = Rufus::Scheduler.new :lockfile => ".rufus-scheduler.lock"
scheduler.every("60") do
...
end
环境:Ubuntu,rails 4,rufus,unicorn,nginx
Unicorn有多个worker,因此上面的“every”任务将在每60秒内被执行多次。
根据这个答案: rufus scheduler running twice each time,我添加了:lockfile选项,并且它起作用了!
但是,从日志中看,似乎“every”任务仍然会尝试调用,导致出现大量错误消息:
E, [2014-05-09T01:59:47.496840 #2747] ERROR -- : cannot schedule, scheduler is down or shutting down (Rufus::Scheduler::NotRunningError)
/home/sohmobile/shared/bundle/ruby/2.1.0/gems/rufus-scheduler-3.0.7/lib/rufus/scheduler.rb:605:in `do_schedule'
/home/sohmobile/shared/bundle/ruby/2.1.0/gems/rufus-scheduler-3.0.7/lib/rufus/scheduler.rb:209:in `every'
/home/sohmobile/releases/20140509014407/config/initializers/task_scheduler.rb:3:in `<top (required)>'
我该如何解决这个问题?
提前感谢您的帮助。