Search code examples
ruby-on-railslinuxscheduled-taskspassenger

rufus scheduler not running in production


I have a rails server running under nginx & passenger. My sheduler.rb looks like this

require 'rufus-scheduler'
my_awesome_job = Rufus::Scheduler.new

my_awesome_job.cron '59 23 * * *' do
    #do something
end

Everything works fine if I set the job for the next 2-3 minutes (for test). But this one, as I need it in production, does not start at 23:59 every day. I don't know where is the problem.

Thanks.


Solution

  • Most likely, this problem is caused by the Rufus scheduler background thread being terminated after Phusion Passenger spawns a child process as part of the smart spawning method.

    Read Spawning methods explained. The specific issue you're suffering from is probably Smart spawning caveat #2: the need to revive threads.

    You need to revive the Rufus scheduler thread using the mechanism in the documentation. I'm not exactly sure which API call you need to make, so maybe you can ask the Rufus scheduler authors.

    Alternatively, you can use the 'direct' spawning method. It's less efficient but it avoids compatibility issues like this.