I've got a script where I am trying to use Rufus-Scheduler to create daily schedules at 1am (based around sunrise and sunset). When I run the code it seems to only run the first scheduler event and won't run any events after it. My understanding is Rufus-Scheduler is supposed to spawn a new thread with each schedule but it looks like it is blocking. Do I need to spawn the schedules off on a new thread? Do I need to create a new scheduler instance for each schedule I'm going to create? I've added a test scheduler at the bottom of the code and it doesn't get created.
Here's the portion of code which relates to rufus-scheduler
def get_todays_show()
this_year = Time.now.year
check_sunset
#the time format that comes back isn't reconginzed by rufus scheduler so recreate it with chronic
sunrise = Chronic.parse("#{@local_sunrise.to_s[0,10]} #{@local_sunrise.to_s[11,8]}" )
sunset = Chronic.parse("#{@local_sunset.to_s[0,10]} #{@local_sunset.to_s[11,8]}" )
schedule_array = create_array_from_csv
schedule_array.each do |sub_array|
earlier = Chronic.parse("#{sub_array[0]} #{this_year} 12:00:01 am")
later = Chronic.parse("#{sub_array[1]} #{this_year} 11:59:59")
range = earlier..later
if range.cover?(Time.now)
@scheduler.at sunset do
madrix_call(sub_array[2].strip)
end
@scheduler.at sunrise do
madrix_call(@off_slot)
end
end
end
end
#set up the scheduler
@scheduler = Rufus::Scheduler.start_new(:frequency => 30.0)
#run it once to handle today
get_todays_show
#the schedule to handle the future
@scheduler.cron '1 1 * * *' do
get_todays_show
p @scheduler.jobs
end
@scheduler.cron '* * * * *' do
p "test schedule - #{Time.now}"
end
@scheduler.join
Do I need to spawn the schedules off on a new thread?
No, rufus-scheduler does it for you.
Do I need to create a new scheduler instance for each schedule I'm going to create?
No, not at all.
Have you tried without setting a frequency (using rufus-scheduler's default frequency)?
Although you are not hitting a rufus-scheduler issue, please read: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
You are not giving any detail about your environment, it's very hard to help you.
Try to iterate from small to big. Have a small schedule thinggy work and then proceed one step after the other.