whenever/README.rdoc

95 lines
3.3 KiB
Plaintext
Raw Normal View History

2009-02-17 00:47:21 +00:00
== Introduction
2009-02-16 03:24:10 +00:00
2009-02-17 01:08:15 +00:00
Whenever is a ruby gem that provides a ruby 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.
2009-02-16 03:24:10 +00:00
== Installation
2009-02-17 01:08:15 +00:00
Regular (non-Rails) install:
$ gem sources -a http://gems.github.com (you only need to run this once)
$ sudo gem install javan-whenever
2009-02-17 00:47:21 +00:00
2009-02-17 01:08:15 +00:00
In a Rails (2.1 or greater) application:
2009-02-16 03:24:10 +00:00
in your "config/environment.rb" file:
Rails::Initializer.run do |config|
config.gem 'javan-whenever', :lib => false, :version => '>= 0.1.4' :source => 'http://gems.github.com'
2009-02-16 03:24:10 +00:00
end
To install this gem (and all other missing gem dependencies), run rake gems:install (use sudo if necessary).
In older versions of Rails:
$ gem sources -a http://gems.github.com (you only need to run this once)
2009-02-17 00:47:21 +00:00
$ gem install javan-whenever
2009-02-16 03:24:10 +00:00
in your "config/environment.rb" file:
Rails::Initializer.run do |config|
...
end
2009-02-17 01:08:15 +00:00
require 'whenever'
2009-02-16 03:24:10 +00:00
2009-02-17 01:08:15 +00:00
NOTE: Requiring the whenever gem inside your Rails application is technically optional. However, if you plan to use something like Capistrano to automatically deploy and write your crontab file, you'll need to have the gem installed on your servers, and requiring it in your app is one to ensure this.
2009-02-16 03:24:10 +00:00
== Getting started
2009-02-17 00:47:21 +00:00
$ cd /my/rails/app
$ wheneverize .
2009-02-16 03:24:10 +00:00
This will create an initial "config/schedule.rb" file you.
== Example schedule.rb file
2009-02-17 00:47:21 +00:00
set :path, '/var/www/apps/my_app' # Whenever will try to use your RAILS_ROOT if this isn't set
set :environment, :production # Whenever defaults to production so you only need to set this for something different
set :cron_log, '/my/cronlog.log' # Where to log (this should NOT be your Rails log)
2009-02-16 03:24:10 +00:00
every 2.hours do
2009-02-17 01:08:15 +00:00
runner "MyModel.some_process" # runners are the script/runners you know and love
rake "my:rake:task" # conveniently run rake tasks
command "/usr/bin/my_great_command" # commands are any unix command
2009-02-16 03:24:10 +00:00
end
2009-02-17 01:08:15 +00:00
every 1.day, :at => '4:30 am' do # If not :at option is set these jobs will run at midnight
runner "DB.Backup", :cron_log => false # You can specify false for no logging or a string with a different log file to override any global logging.
2009-02-16 03:24:10 +00:00
end
every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
2009-02-17 01:08:15 +00:00
runner "SomeModel.ladeeda"
2009-02-16 03:24:10 +00:00
end
every :sunday do # Use any day of the week or :weekend, :weekday
runner "Task.do_something_great"
end
== Cron output
2009-02-17 00:47:21 +00:00
$ cd /my/rails/app
$ whenever
2009-02-16 03:24:10 +00:00
And you'll see your schedule.rb converted to cron sytax
== Capistrano integration
in your "config/deploy.rb" file do something like:
2009-02-17 00:47:21 +00:00
after "deploy:symlink", "deploy:write_crontab"
namespace :deploy do
desc "write the crontab file"
task :write_crontab, :roles => :app do
run "cd #{release_path} && whenever --write-crontab"
2009-02-17 00:47:21 +00:00
end
end
2009-02-16 03:24:10 +00:00
2009-02-17 19:38:37 +00:00
By mixing and matching the --load-file and --user options with your various :roles in Capistrano it is entirely possible to deploy different crontab schedules under different users to all your various servers. Get creative!
USING THE --write-crontab OPTION WILL COMPLETELY OVERWRITE ANY EXISTING CRONTAB ENTRIES!
2009-02-16 03:24:10 +00:00
------------------------------------------------------------
Better documentation on the way!