Rufus scheduler and daemon script is not working in rails

835 Views Asked by At

I was making a script that runs periodically to make some code inside my rails app using rufus scheduler (I used it with daemon specifically to work on production server). But it is not working at all as it terminates and kill the process.

Here is my script/rufus_schedule file

#!/usr/bin/env ruby

root = File.expand_path(File.join(File.dirname(__FILE__), '..'))

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))

require 'rubygems'
require 'rufus/scheduler'
gem 'daemons'
require 'daemons'

options = {
  :dir_mode   => :normal,
  :dir        => File.join(root,'log'),
  :log_output => true,
  :backtrace  => true,
  :multiple   => false
}

Daemons.run_proc("rufus_schedule", options) do
  scheduler = Rufus::Scheduler.start_new

  scheduler.every '10s' do
    BloodDonationUtil.clear_requests_after(7)
  end
end
1

There are 1 best solutions below

3
On

I don't know what you mean by "kill the process", I guess you mean "it exits immediately".

Please read: https://github.com/jmettraux/rufus-scheduler#schedulerjoin

Add at the end of your script:

scheduler.join