Created
June 20, 2011 23:24
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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