0

I need some code executed once per day. Can be more than once a day and missing a day isn't the end of the world. That code will make sure users get some bonus points based on certain criteria. I'll keep track if they've already received the bonus points so it doesn't double up..

Some simple cron job calling a particular controller once in a while is perfect:

curl http://localhost/tasks/pulse

Of course a real crontab entry works great. Or is there an internal mechanism for this kind of thing in Rails? I'm using the latest stable Rails (currently 3.2.9).

The only wrinkle is this needs to work in Heroku too.

I just noticed Heroku's Scheduler. Looks great for Heroku. I can just run those tasks in my dev/test environment manually. Is this the best way to handle pulses/cron jobs in Rails? With rake tasks? Easy to incorporate running rake tasks in tests?

at.
  • 50,922
  • 104
  • 292
  • 461

2 Answers2

0

You could check out this gem called whenever its a Ruby gem that provides a clear syntax for writing and deploying cron jobs. It's well maintained, not used it on Heroku myself but worth a look.

You can do loads of stuff like

every 3.hours do
  runner "MyModel.some_process"
  rake "my:rake:task"
  command "/usr/bin/my_great_command"
end
cih
  • 1,960
  • 1
  • 16
  • 27
  • Looks amazing, and its all within rails? No external things need to run to give whenever its pulse? Will it work in heroku? – at. Nov 24 '12 at 00:22
  • Actually having looked into it further here (http://stackoverflow.com/questions/8619754/whenever-gem-running-cron-jobs-on-heroku) looks like its not suitable for use on heroku as the whenever gem is just a nice ruby way to write cron jobs and deploy them, the crontab would not persist on heroku. Sorry but I guess my initial answer was not much a help, a good solution if you're not using heroku in future though maybe. – cih Nov 24 '12 at 00:33
  • What about using http://godrb.com/ to create a worker that is constantly running and just makes an http request once a day in a loop, that could work. – cih Nov 24 '12 at 00:40
0

The Heroku Scheduler works great and is easy to set up!

C.J. Bordeleau
  • 197
  • 3
  • 12