Skip to content

Instantly share code, notes, and snippets.

@jamesarosen
Created November 30, 2009 20:15
Show Gist options
  • Save jamesarosen/245702 to your computer and use it in GitHub Desktop.
Save jamesarosen/245702 to your computer and use it in GitHub Desktop.
# from http://missingfeature.com/scheduling-crons-with-delayedjob?c=1
class DjCron
def self.step(action, period, change = {})
next_at = Time.now.change(change) + period
puts "Performing #{action.to_s} and rescheduling at #{next_at.to_s}"
self.reschedule_at(next_at, action, period, change)
end
def self.reschedule_at(send_at, action, period, change = {})
method = Delayed::PerformableMethod.new(self, :step, [action,period, change])
Delayed::Job.enqueue(method, 0, send_at)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment