Rufus scheduler running multiple times with unicorn, fixed with :lockfile, but how to eliminate the error msg?

对着背影说爱祢 提交于 2019-12-22 04:25:06

问题


scheduler = Rufus::Scheduler.new :lockfile => ".rufus-scheduler.lock"

scheduler.every("60") do
...
end

Environment: Ubuntu, rails 4, rufus, unicorn, nginx

Unicorn has multiple workers, so the above 'every' task will be executed multiple times every 60 seconds.

According to the answer for this one: rufus scheduler running twice each time , I added :lockfile option, and it works!

However, from the log, it seems that the 'every' task still tries to be called, resulting in a lot of error messages:

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)>'

How can I solve this issue?

Thanks in advance.


回答1:


This could solve your issue:

require 'rufus-scheduler'

scheduler = Rufus::Scheduler.new(:lockfile => ".rufus-scheduler.lock")

unless scheduler.down?

  scheduler.every("60") do
    # ...
  end
end


来源:https://stackoverflow.com/questions/23556556/rufus-scheduler-running-multiple-times-with-unicorn-fixed-with-lockfile-but-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!