Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 0.57 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #The following assumes an object named "obj" with an action named "meth" that you want to execute at a certain time.
  2. #It is assumed that 'obj' has some notion of what weekday and time (hours and minutes) it needs to be executed.  
  3. #For the purposes of this example, it will be attached directly to obj., but could just as easily come from some associated object.
  4. desc "This task is called by the Heroku cron add-on"
  5. task :cron => :environment do
  6.   current_time = Time.now
  7.   if obj.day == current_time.wday && obj.hour == current_time.hour
  8.     sleep(obj.min * 60)
  9.     obj.meth
  10.   end
  11. end