Whenever: A Ruby DSL for Defining Cron Jobs
It has always been a trend with Rubyists to take things that have poor interfaces and give them better ones. Javan Makhmali from Inkling Markets has lived up to this trend, and given us Whenever, a library that wraps cron's syntax with a Ruby API (cron being a UNIX task scheduling tool).
Whenever can be tightly integrated with Rails (providing application specific commands such as "rake" and "runner" from the API – see an example here), but can also be run as a standalone program. Whenever outputs valid crontab syntax, and can even write the crontab file for you!
Whenever helps you keep your cron jobs with your code so that there is no separation of logic. Since Whenever is a wrapper for cron, however, it's really focused on on UNIX and UNIX-like machines. While there are some cron implementations for Windows, Whenever wasn't really designed for this purpose.
If Whenever is of interest to you, check out the GitHub page, the blog post of Javan's workplace, and the Railscast by Ryan Bates.
Note: This post was written by Ari Brown.
June 9, 2009 at 9:47 pm
Something like this could probably be developed for Windows scheduled tasks. It is possible to import an XML document into the task scheduler from the command line to set up tasks.
If only there was a fast, delightful XML parser with a great library that could generate XML, and a way of making system calls in Ruby, we'd be golden.
*wink, wink*
June 9, 2009 at 11:09 pm
Doesn't work when there are multiple versions of Rails installed. See this bug: http://github.com/javan/whenever/issues#issue/1
June 10, 2009 at 1:32 am
The Perl folks when down this path of rewriting much of the Unix tools chain so as to take advantage of Perl's inherent goodness. But today we still use Vixie Cron and GNU grep, etc. Just learn the existing tools and be done with it.
June 10, 2009 at 11:21 am
I already see 3 libraries on the RAA that provide a cron interface - cronedit, crontab and jobmanager. What does whenever do that they don't?
June 10, 2009 at 2:28 pm
@Daniel, I'm guessing tight Rails integration. Oh, it also has a cute name and it's on github.
June 10, 2009 at 11:58 pm
Andrew: good point, except: vixie cron is pretty wretched. It doesn't set up the environment like you'd expect, and it totally malfunctions on files that don't end in newlines. We, as a civilization, can do better.
June 11, 2009 at 8:43 am
Biggest problem in setting up cron jobs for Rails apps is not cron's syntax itself. It's pretty easy to learn and use. What I find annoying is need for specifying PATH and other variables because not every cron setup does that. What I usually do is to set up wrapper (as shell script) around rake tasks I need to run and execute them from within cron.
I wonder if Whenever solves this issue...
June 19, 2009 at 3:36 am
Been using cron for 20 years without a problem.
Maybe the capistrano integration could make it worth a look.