Cron jobs in Ruby
Go to file
2010-10-18 18:51:27 -04:00
bin allow identifier for writes. fix fight over -c 2010-09-27 18:21:21 -04:00
lib added a built-in capistrano recipe 2010-10-18 18:51:27 -04:00
test runners for Rails 3 2010-10-18 12:08:28 -04:00
.gitignore ignore vim metafiles 2010-07-03 22:55:32 +08:00
CHANGELOG.rdoc Fixed regex related bugs. Release v0.5.3 2010-09-24 13:41:05 -04:00
Rakefile use aaronh-chronic which is ruby 1.9.2 compatible 2010-09-15 22:05:47 -04:00
README.rdoc added a built-in capistrano recipe 2010-10-18 18:51:27 -04:00
whenever.gemspec Fixed regex related bugs. Release v0.5.3 2010-09-24 13:41:05 -04:00

== Introduction

Whenever is a Ruby gem that provides a clear syntax for defining cron jobs. It outputs valid cron syntax and can even write your crontab file for you. It is designed to work well with Rails applications and can be deployed with Capistrano. Whenever works fine independently as well.

Ryan Bates created a great Railscast about Whenever: http://railscasts.com/episodes/164-cron-in-ruby

Discussion: http://groups.google.com/group/whenever-gem

== Installation
  
$ sudo gem install whenever

== Getting started

  $ cd /my/rails/app
  $ wheneverize .

This will create an initial "config/schedule.rb" file you.

== Example schedule.rb file
  
  every 3.hours do
    runner "MyModel.some_process"       
    rake "my:rake:task"                 
    command "/usr/bin/my_great_command"
  end

  every 1.day, :at => '4:30 am' do 
    runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
  end

  every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
    runner "SomeModel.ladeeda"
  end

  every :sunday, :at => '12pm' do # Use any day of the week or :weekend, :weekday 
    runner "Task.do_something_great"
  end

More examples on the wiki: http://wiki.github.com/javan/whenever/instructions-and-examples

== Define your own job types

Whenever ships with three pre-defined job types: command, runner, and rake. You can define your own with <code>job_type</code>.

For example:

  job_type :awesome, '/usr/local/bin/awesome :task :fun_level'
  
  every 2.hours do
    awesome "party", :fun_level => "extreme"
  end
  
Would run <code>/usr/local/bin/awesome party extreme</code> every two hours. <code>:task</code> is always replaced with the first argument, and any additional <code>:whatevers</code> are replaced with the options passed in or by variables that have been defined with <code>set</code>.

The default job types that ship with Whenever are defined like so:

  job_type :command, ":task"
  job_type :runner,  "cd :path && script/runner -e :environment ':task'"
  job_type :rake,    "cd :path && RAILS_ENV=:environment /usr/bin/env rake :task"

If a <code>:path</code> is not set it will default to the directory in which <code>whenever</code> was executed. <code>:environment</code> will default to 'production'.

== Cron output

  $ cd /my/rails/app
  $ whenever

And you'll see your schedule.rb converted to cron sytax. Note: running `whenever' with no options does not display your current crontab file, it simply shows you the output of converting your schedule.rb file.

== Capistrano integration

Use the built-in Capistrano recipe for easy crontab updates with deploys.

In your "config/deploy.rb" file:

  require "whenever/capistrano"

Take a look at the recipe for options you can set. http://github.com/javan/whenever/blob/master/lib/whenever/capistrano.rb
For example, if you're using bundler do this:

  set :whenever_command, "bundle exec whenever"
  require "whenever/capistrano"


== Credit

Whenever was created for use at Inkling (http://inklingmarkets.com) where I work. Their take on it: http://blog.inklingmarkets.com/2009/02/whenever-easy-way-to-do-cron-jobs-from.html

While building Whenever, I learned a lot by digging through the source code of Capistrano - http://github.com/jamis/capistrano

== Discussion / Feedback / Issues / Bugs

For general discussion and questions, please use the google group: http://groups.google.com/group/whenever-gem

If you've found a genuine bug or issue, please use the Issues section on github: http://github.com/javan/whenever/issues

== License

Copyright (c) 2009+ Javan Makhmali

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.