From 16fa99c875e37d36f4465ce47f13f2e04e164f01 Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Thu, 5 Apr 2012 20:18:11 -0700 Subject: [PATCH] Support custom capistrano role, fixes #113 --- Changes.md | 6 ++++++ lib/sidekiq/capistrano.rb | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Changes.md b/Changes.md index a9ebaf85..1c282703 100644 --- a/Changes.md +++ b/Changes.md @@ -1,3 +1,9 @@ +HEAD +----------- + +- Add support for a custom Capistrano role to limit Sidekiq to + a set of machines. [#113] + 0.11.1 ----------- diff --git a/lib/sidekiq/capistrano.rb b/lib/sidekiq/capistrano.rb index 344bd52e..78eaf962 100644 --- a/lib/sidekiq/capistrano.rb +++ b/lib/sidekiq/capistrano.rb @@ -3,27 +3,28 @@ Capistrano::Configuration.instance.load do after "deploy", "sidekiq:restart" _cset(:sidekiq_timeout) { 10 } + _cset(:sidekiq_role) { :app } namespace :sidekiq do desc "Quiet sidekiq (stop accepting new work)" - task :quiet do + task :quiet, :roles => lambda { fetch(:sidekiq_role) } do run "cd #{current_path} && if [ -f #{current_path}/tmp/pids/sidekiq.pid ]; then bundle exec sidekiqctl quiet #{current_path}/tmp/pids/sidekiq.pid ; fi" end desc "Stop sidekiq" - task :stop do + task :stop, :roles => lambda { fetch(:sidekiq_role) } do run "cd #{current_path} && if [ -f #{current_path}/tmp/pids/sidekiq.pid ]; then bundle exec sidekiqctl stop #{current_path}/tmp/pids/sidekiq.pid #{fetch :sidekiq_timeout} ; fi" end desc "Start sidekiq" - task :start do + task :start, :roles => lambda { fetch(:sidekiq_role) } do rails_env = fetch(:rails_env, "production") run "cd #{current_path} ; nohup bundle exec sidekiq -e #{rails_env} -C #{current_path}/config/sidekiq.yml -P #{current_path}/tmp/pids/sidekiq.pid >> #{current_path}/log/sidekiq.log 2>&1 &" end desc "Restart sidekiq" - task :restart do + task :restart, :roles => lambda { fetch(:sidekiq_role) } do stop start end