Whenever - Making cron easy for Rails

1 minute read

I use rake tasks pretty much, well… everywhere in my Rails programs. They’re amazingly handy for automating things I want to keep track of, mailing things out to people regularly and just generally doing useful stuff.

Firing them on a timer though usually involves going in and manually editing cron with the infamous crontab -e

Hand-edited is no problem for me, but when distributing code it is a little annoying since you usually have to put instructions in for people to do it manually and its one of those things people always forget to do.

Enter whenever. Basically, it’s a nice little gem you can install to handle all your cron pain. It’s one of those things you don’t even realize you really need till you install it and start using it.

Took me about 10 minutes to branch git, config whenever via the handy DSL in the schedule.rb file and then deploy it via capistrano to get auto-updated cron tasks on each deploy to an app I’ve got in production. Bliss.

I’ve liked it so much (and I use rake so much), I’ve actually dropped it into my alakazam Rails 2.3 template for revving up and starting new, and fresh Rails apps all the time (ok, admittedly, probably not the highest praise in the world, but I do only select the best… ;-) ).

If you’re thinking of using it but want some examples, check out the Ryan Bates’ RailsCast on whenever.

dev ruby rails