fixed conflict

This commit is contained in:
Javan Makhmali 2010-10-20 17:13:09 -04:00
commit 3e7e7f1401
2 changed files with 43 additions and 12 deletions

View File

@ -84,24 +84,24 @@ And you'll see your schedule.rb converted to cron sytax. Note: running `whenever
== 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
desc "Update the crontab file"
task :update_crontab, :roles => :db do
run "cd #{release_path} && whenever --update-crontab #{application}"
end
end
require "whenever/capistrano"
This will update your crontab file, leaving any existing entries unharmed. When using the `--update-crontab` option, Whenever will only update the entries in your crontab file related to the current schedule.rb file. You can replace the `#{application}` 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 `--write-crontab` 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 `--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!
If you want to override a variable (like your environment) at the time of deployment you can do so with the `--set` option: http://wiki.github.com/javan/whenever/setting-variables-on-the-fly
== 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

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