Permalink
Browse files

added a built-in capistrano recipe

  • Loading branch information...
1 parent 0055c36 commit 436255e4a58452b0a28448d4d9a16804854147fd @javan javan committed Oct 18, 2010
Showing with 38 additions and 13 deletions.
  1. +7 −13 README.rdoc
  2. +31 −0 lib/whenever/capistrano.rb
View
20 README.rdoc
@@ -70,24 +70,18 @@ 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
-
-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.
+ require "whenever/capistrano"
-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.
+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:
-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!
+ set :whenever_command, "bundle exec whenever"
+ require "whenever/capistrano"
-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
View
31 lib/whenever/capistrano.rb
@@ -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

0 comments on commit 436255e

Please sign in to comment.