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

StackOverflow https://stackoverflow.com/questions/23556556

質問

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.

役に立ちましたか?

解決

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top