Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 804
user3618929 Avatar asked May 09 '14 04:05

user3618929


1 Answers

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
like image 151
jmettraux Avatar answered Jan 03 '23 15:01

jmettraux