2012-02-26 23:36:30 -05:00
|
|
|
Capistrano::Configuration.instance.load do
|
2012-08-19 14:31:20 -04:00
|
|
|
before "deploy:update_code", "sidekiq:quiet"
|
2012-04-16 21:56:41 -04:00
|
|
|
after "deploy:stop", "sidekiq:stop"
|
|
|
|
after "deploy:start", "sidekiq:start"
|
|
|
|
after "deploy:restart", "sidekiq:restart"
|
2012-02-26 23:36:30 -05:00
|
|
|
|
2012-09-11 16:26:12 -04:00
|
|
|
_cset(:sidekiq_timeout) { 10 }
|
|
|
|
_cset(:sidekiq_role) { :app }
|
|
|
|
_cset(:sidekiq_pid) { "#{current_path}/tmp/pids/sidekiq.pid" }
|
|
|
|
_cset(:sidekiq_processes) { 1 }
|
2012-03-08 23:58:51 -05:00
|
|
|
|
2012-02-26 23:36:30 -05:00
|
|
|
namespace :sidekiq do
|
2012-09-11 16:26:12 -04:00
|
|
|
def for_each_process(&block)
|
|
|
|
0.upto(fetch(:sidekiq_processes) - 1) do |process|
|
|
|
|
yield process == 0 ? "#{fetch(:sidekiq_pid)}" : "#{fetch(:sidekiq_pid)}-#{process}"
|
|
|
|
end
|
|
|
|
end
|
2012-02-26 23:36:30 -05:00
|
|
|
|
2012-03-08 23:58:51 -05:00
|
|
|
desc "Quiet sidekiq (stop accepting new work)"
|
2012-04-20 13:12:21 -04:00
|
|
|
task :quiet, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
|
2012-09-11 16:26:12 -04:00
|
|
|
for_each_process do |pid_file|
|
|
|
|
run "if [ -d #{current_path} ] && [ -f #{pid_file} ]; then cd #{current_path} && #{fetch(:bundle_cmd, "bundle")} exec sidekiqctl quiet #{pid_file} ; fi"
|
|
|
|
end
|
2012-02-26 23:36:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "Stop sidekiq"
|
2012-04-20 13:12:21 -04:00
|
|
|
task :stop, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
|
2012-09-11 16:26:12 -04:00
|
|
|
for_each_process do |pid_file|
|
|
|
|
run "if [ -d #{current_path} ] && [ -f #{pid_file} ]; then cd #{current_path} && #{fetch(:bundle_cmd, "bundle")} exec sidekiqctl stop #{pid_file} #{fetch :sidekiq_timeout} ; fi"
|
|
|
|
end
|
2012-02-26 23:36:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "Start sidekiq"
|
2012-04-20 13:12:21 -04:00
|
|
|
task :start, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
|
2012-02-26 23:36:30 -05:00
|
|
|
rails_env = fetch(:rails_env, "production")
|
2012-09-11 16:26:12 -04:00
|
|
|
for_each_process do |pid_file|
|
|
|
|
run "cd #{current_path} ; nohup #{fetch(:bundle_cmd, "bundle")} exec sidekiq -e #{rails_env} -C #{current_path}/config/sidekiq.yml -P #{pid_file} >> #{current_path}/log/sidekiq.log 2>&1 &", :pty => false
|
|
|
|
end
|
2012-02-26 23:36:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "Restart sidekiq"
|
2012-04-20 13:12:21 -04:00
|
|
|
task :restart, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
|
2012-02-26 23:36:30 -05:00
|
|
|
stop
|
|
|
|
start
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|