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

1

9
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.

Cerous answered 9/5, 2014 at 4:20 Comment(0)
N
17

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
Noncombatant answered 9/5, 2014 at 5:19 Comment(1)
If that's the case, then accept my answer and vote it up. Thanks in advance :-)Noncombatant

© 2022 - 2024 — McMap. All rights reserved.