Merge pull request #138 from cgriego/master

Capistrano tasks enhancements
This commit is contained in:
Javan Makhmali 2011-06-14 06:47:30 -07:00
commit bf679b02a9

View File

@ -1,32 +1,62 @@
Capistrano::Configuration.instance(:must_exist).load do Capistrano::Configuration.instance(:must_exist).load do
_cset(:whenever_roles) { :db } _cset(:whenever_roles) { :db }
_cset(:whenever_command) { "whenever" } _cset(:whenever_command) { "whenever" }
_cset(:whenever_identifier) { application } _cset(:whenever_identifier) { fetch :application }
_cset(:whenever_environment) { "production" } _cset(:whenever_environment) { fetch :rails_env, "production" }
_cset(:whenever_update_flags) { "--update-crontab #{whenever_identifier} --set environment=#{whenever_environment}" } _cset(:whenever_update_flags) { "--update-crontab #{fetch :whenever_identifier} --set environment=#{fetch :whenever_environment}" }
_cset(:whenever_clear_flags) { "--clear-crontab #{whenever_identifier}" } _cset(:whenever_clear_flags) { "--clear-crontab #{fetch :whenever_identifier}" }
# Disable cron jobs at the begining of a deploy. # Disable cron jobs at the begining of a deploy.
after "deploy:update_code", "whenever:clear_crontab" after "deploy:update_code", "whenever:clear_crontab"
# Write the new cron jobs near the end. # Write the new cron jobs near the end.
after "deploy:symlink", "whenever:update_crontab" after "deploy:symlink", "whenever:update_crontab"
# If anything goes wrong, undo. # If anything goes wrong, undo.
after "deploy:rollback", "whenever:update_crontab" after "deploy:rollback", "whenever:update_crontab"
namespace :whenever do namespace :whenever do
desc "Update application's crontab entries using Whenever" desc <<-DESC
task :update_crontab, :roles => whenever_roles do Update application's crontab entries using Whenever. You can configure \
# Hack by Jamis to skip a task if the role has no servers defined. http://tinyurl.com/ckjgnz the command used to invoke Whenever by setting the :whenever_command \
next if find_servers_for_task(current_task).empty? variable, which can be used with Bundler to set the command to \
run "cd #{current_path} && #{whenever_command} #{whenever_update_flags}" "bundle exec whenever". You can configure the identifier used by setting \
the :whenever_identifier variable, which defaults to the same value configured \
for the :application variable. You can configure the environment by setting \
the :whenever_environment variable, which defaults to the same value \
configured for the :rails_env variable which itself defaults to "production". \
Finally, you can completely override all arguments to the Whenever command \
by setting the :whenever_update_flags variable. Additionally you can configure \
which servers the crontab is updated on by setting the :whenever_roles variable.
DESC
task :update_crontab do
options = { :roles => fetch(:whenever_roles) }
if find_servers(options).any?
on_rollback do
if fetch :previous_release
run "cd #{fetch :previous_release} && #{fetch :whenever_command} #{fetch :whenever_update_flags}", options
else
run "cd #{fetch :release_path} && #{fetch :whenever_command} #{fetch :whenever_clear_flags}", options
end
end
run "cd #{fetch :current_path} && #{fetch :whenever_command} #{fetch :whenever_update_flags}", options
end
end end
desc "Clear application's crontab entries using Whenever" desc <<-DESC
task :clear_crontab, :roles => whenever_roles do Clear application's crontab entries using Whenever. You can configure \
next if find_servers_for_task(current_task).empty? the command used to invoke Whenever by setting the :whenever_command \
run "cd #{release_path} && #{whenever_command} #{whenever_clear_flags}" variable, which can be used with Bundler to set the command to \
"bundle exec whenever". You can configure the identifier used by setting \
the :whenever_identifier variable, which defaults to the same value configured \
for the :application variable. Finally, you can completely override all \
arguments to the Whenever command by setting the :whenever_clear_flags variable. \
Additionally you can configure which servers the crontab is cleared on by setting \
the :whenever_roles variable.
DESC
task :clear_crontab do
options = { :roles => whenever_roles }
run "cd #{fetch :release_path} && #{fetch :whenever_command} #{fetch :whenever_clear_flags}", options if find_servers(options).any?
end end
end end
end
end