Search code examples
ruby-on-railssingletonrufus-scheduler

Rails rufus-scheduler jobs returning nil


I'm using rufus-scheduler to schedule jobs at a certain date through the following code:

  job = Rufus::Scheduler.singleton.schedule_at @post.read_attribute(:parse_time).to_s do

  end

I then save the id of that job in my post class

  @post.update_attribute(:job_id, job.id)

However, if I try and access that job again by calling:

  Rufus::Scheduler.singleton.job(@post.read_attribute(:job_id)).unschedule

I get an error because the job is nil. If I try and look at the jobs of the Scheduler by calling:

  Rufus::Scheduler.singleton.jobs

I get a blank array. Can anyone explain why my jobs aren't saving properly kept / being tracked?

Here's my initialization file for the scheduler. Do I have to do anything to enable singleton though? Or does it come with rails automatically:

require 'rufus-scheduler'

# Create singleton rufus scheduler
s = Rufus::Scheduler.singleton

Solution

  • rufus-scheduler doesn't keep triggered jobs around.

    Your job has probably triggered and is gone.