Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Whenever: A Ruby DSL for Defining Cron Jobs

By Peter Cooper / June 9, 2009

clock.png 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.


  1. Stephen Stillwater says:

    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*

  2. Chris Johnston says:

    Doesn't work when there are multiple versions of Rails installed. See this bug:

  3. Andrew Gilmartin says:

    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.

  4. Daniel Berger says:

    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?

  5. Jason L Perry says:

    @Daniel, I'm guessing tight Rails integration. Oh, it also has a cute name and it's on github.

  6. Phil says:

    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.

  7. Hubert Łępicki says:

    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...

  8. Andy Watts says:

    Been using cron for 20 years without a problem.
    Maybe the capistrano integration could make it worth a look.

Other Posts to Enjoy

Twitter Mentions