Skip to content

Instantly share code, notes, and snippets.

@weyus
Created June 20, 2011 23:24
Show Gist options
  • Save weyus/1036855 to your computer and use it in GitHub Desktop.
Save weyus/1036855 to your computer and use it in GitHub Desktop.
Cron job to allow for arbitrarily timed Heroku tasks without using a worker dyno.
#The following assumes an object named "obj" with an action named "meth" that you want to execute at a certain time.
#It is assumed that 'obj' has some notion of what weekday and time (hours and minutes) it needs to be executed.
#For the purposes of this example, it will be attached directly to obj., but could just as easily come from some associated object.
desc "This task is called by the Heroku cron add-on"
task :cron => :environment do
current_time = Time.now
if obj.day == current_time.wday && obj.hour == current_time.hour
sleep(obj.min * 60)
obj.meth
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment