added a built-in capistrano recipe

This commit is contained in:
Javan Makhmali 2010-10-18 18:51:27 -04:00
parent 0055c36aef
commit 436255e4a5
2 changed files with 38 additions and 13 deletions

View File

@ -70,24 +70,18 @@ And you'll see your schedule.rb converted to cron sytax. Note: running `whenever
== Capistrano integration == Capistrano integration
In your "config/deploy.rb" file do something like: Use the built-in Capistrano recipe for easy crontab updates with deploys.
after "deploy:symlink", "deploy:update_crontab" In your "config/deploy.rb" file:
namespace :deploy do require "whenever/capistrano"
desc "Update the crontab file"
task :update_crontab, :roles => :db do
run "cd #{release_path} && whenever --update-crontab #{application}"
end
end
This will update your crontab file, leaving any existing entries unharmed. When using the <code>--update-crontab</code> option, Whenever will only update the entries in your crontab file related to the current schedule.rb file. You can replace the <code>#{application}</code> with any identifying string you'd like. You can have any number of apps deploy to the same crontab file peacefully given they each use a different identifier. 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:
If you wish to simply overwrite your crontab file each time you deploy, use the <code>--write-crontab</code> option. This is ideal if you are only working with one app and every crontab entry is contained in a single schedule.rb file. set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"
By mixing and matching the <code>--load-file</code> and <code>--user</code> 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!
If you want to override a variable (like your environment) at the time of deployment you can do so with the <code>--set</code> option: http://wiki.github.com/javan/whenever/setting-variables-on-the-fly
== Credit == Credit

View File

@ -0,0 +1,31 @@
Capistrano::Configuration.instance(:must_exist).load do
_cset(:whenever_roles) { :db }
_cset(:whenever_command) { "whenever" }
_cset(:whenever_identifier) { application }
_cset(:whenever_update_flags) { "--update-crontab #{whenever_identifier}" }
_cset(:whenever_clear_flags) { "--clear-crontab #{whenever_identifier}" }
# Disable cron jobs at the begining of a deploy.
after "deploy:update_code", "whenever:clear_crontab"
# Write the new cron jobs near the end.
after "deploy:symlink", "whenever:update_crontab"
# If anything goes wrong, undo.
after "deploy:rollback", "whenever:update_crontab"
namespace :whenever do
desc "Update application's crontab entries using Whenever"
task :update_crontab, :roles => whenever_roles do
# Hack by Jamis to skip a task if the role has no servers defined. http://tinyurl.com/ckjgnz
next if find_servers_for_task(current_task).empty?
run "cd #{current_path} && #{whenever_command} #{whenever_update_flags}"
end
desc "Clear application's crontab entries using Whenever"
task :clear_crontab, :roles => whenever_roles do
next if find_servers_for_task(current_task).empty?
run "cd #{release_path} && #{whenever_command} #{whenever_clear_flags}"
end
end
end