1. Whenever: A Hidden Gem

    After learning cron syntax, figuring out what the PATH is during cron execution and how to set it in my crontab, and documenting my crontab within my application, I discovered Whenever.  Javan Makhmali’s Whenever gem allows you to write self-documenting ruby in your application to define your cron jobs, then integrates beautifully with Capistrano to update  your crontab on deploy.  It also saves me from having to lookup cron syntax every few months when I need to edit something (and have, of course, forgotten the syntax).

    The documentation for Whenever is very good, and there’s even a Railscast that provides a step by step.  But there is one setting not mentioned anywhere, which I only found digging through the code:

    set :set_path_automatically, false

    Nominally, Whenever writes a PATH=... line before it lists your cron jobs.  This is fine most of the time, but on some systems (like Joyent’s SunOS 5.11) the extended Vixie Cron syntax (the standard used on most *nix systems) is not supported.  As such, you may see an error like

    crontab: error on previous line; unexpected character found in line.

    if PATH is set in your crontab.  So, disable it in your schedule.rb and get back to real work.

    p.s. Will Tumblr ever create a post type for code?

     

    tags:  ruby  error  gem  rails 

    Comments
  2. blog comments powered by Disqus