2013-10-15 17:29:47 -04:00
|
|
|
namespace :load do
|
|
|
|
task :defaults do
|
|
|
|
|
2013-10-28 11:02:13 -04:00
|
|
|
set :sidekiq_default_hooks, ->{ true }
|
|
|
|
|
2013-10-22 20:33:07 -04:00
|
|
|
# If you need a special boot commands
|
2013-10-28 11:01:36 -04:00
|
|
|
#
|
2013-10-22 20:33:07 -04:00
|
|
|
# set :sidekiq_cmd, ->{ "bundle exec sidekiq" }
|
|
|
|
# set :sidekiqctl_cmd, ->{ "bundle exec sidekiqctl" }
|
|
|
|
set :sidekiq_cmd, ->{ }
|
|
|
|
set :sidekiqctl_cmd, ->{ }
|
2013-10-15 17:29:47 -04:00
|
|
|
|
2013-10-22 20:33:07 -04:00
|
|
|
# must be relative to Rails.root. If this changes, you'll need to manually
|
|
|
|
# stop the existing sidekiq process.
|
|
|
|
set :sidekiq_pid, ->{ "tmp/sidekiq.pid" }
|
|
|
|
|
|
|
|
# "-d -i INT -P PATH" are added automatically.
|
2013-10-22 17:05:38 -04:00
|
|
|
set :sidekiq_options, ->{ "-e #{fetch(:rails_env, 'production')} -C #{current_path}/config/sidekiq.yml -L #{current_path}/log/sidekiq.log" }
|
2013-10-15 17:29:47 -04:00
|
|
|
|
|
|
|
set :sidekiq_timeout, ->{ 10 }
|
2013-10-22 20:33:07 -04:00
|
|
|
set :sidekiq_role, ->{ :app }
|
|
|
|
set :sidekiq_processes, ->{ 1 }
|
2013-10-15 17:29:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-15 14:11:44 -04:00
|
|
|
namespace :sidekiq do
|
|
|
|
def for_each_process(&block)
|
|
|
|
fetch(:sidekiq_processes).times do |idx|
|
|
|
|
yield((idx == 0 ? "#{fetch(:sidekiq_pid)}" : "#{fetch(:sidekiq_pid)}-#{idx}"), idx)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Quiet sidekiq (stop accepting new work)"
|
|
|
|
task :quiet do
|
|
|
|
on roles fetch(:sidekiq_role) do
|
2013-10-29 13:08:46 -04:00
|
|
|
for_each_process do |pid_file, idx|
|
|
|
|
if test "[ -f #{current_path}/#{pid_file} ]"
|
|
|
|
within current_path do
|
2013-10-22 20:33:07 -04:00
|
|
|
if fetch(:sidekiqctl_cmd)
|
|
|
|
execute fetch(:sidekiqctl_cmd), 'quiet', "#{current_path}/#{pid_file}"
|
|
|
|
else
|
|
|
|
execute :bundle, :exec, :sidekiqctl, 'quiet', "#{current_path}/#{pid_file}"
|
|
|
|
end
|
2013-10-15 17:29:47 -04:00
|
|
|
end
|
|
|
|
end
|
2013-10-15 14:11:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Stop sidekiq"
|
|
|
|
task :stop do
|
|
|
|
on roles fetch(:sidekiq_role) do
|
2013-10-29 13:08:46 -04:00
|
|
|
for_each_process do |pid_file, idx|
|
|
|
|
if test "[ -f #{current_path}/#{pid_file} ]"
|
|
|
|
within current_path do
|
2013-10-22 20:33:07 -04:00
|
|
|
if fetch(:sidekiqctl_cmd)
|
|
|
|
execute fetch(:sidekiqctl_cmd), 'stop', "#{current_path}/#{pid_file}", fetch(:sidekiq_timeout)
|
|
|
|
else
|
|
|
|
execute :bundle, :exec, :sidekiqctl, 'stop', "#{current_path}/#{pid_file}", fetch(:sidekiq_timeout)
|
|
|
|
end
|
2013-10-15 17:29:47 -04:00
|
|
|
end
|
|
|
|
end
|
2013-10-15 14:11:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Start sidekiq"
|
|
|
|
task :start do
|
|
|
|
on roles fetch(:sidekiq_role) do
|
2013-10-15 14:34:43 -04:00
|
|
|
rails_env = fetch(:rails_env, "production")
|
2013-10-15 17:29:47 -04:00
|
|
|
within current_path do
|
|
|
|
for_each_process do |pid_file, idx|
|
2013-10-22 20:33:07 -04:00
|
|
|
if fetch(:sidekiq_cmd)
|
2013-10-28 11:01:36 -04:00
|
|
|
execute fetch(:sidekiq_cmd), "-d -i #{idx} -P #{pid_file} #{fetch(:sidekiq_options)}"
|
2013-10-22 20:33:07 -04:00
|
|
|
else
|
2013-10-28 11:01:36 -04:00
|
|
|
execute :bundle, :exec, :sidekiq, "-d -i #{idx} -P #{pid_file} #{fetch(:sidekiq_options)}"
|
2013-10-22 20:33:07 -04:00
|
|
|
end
|
2013-10-15 17:29:47 -04:00
|
|
|
end
|
2013-10-15 14:11:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Restart sidekiq"
|
|
|
|
task :restart do
|
2013-10-22 20:33:07 -04:00
|
|
|
invoke 'sidekiq:stop'
|
|
|
|
invoke 'sidekiq:start'
|
2013-10-15 14:11:44 -04:00
|
|
|
end
|
|
|
|
|
2013-10-28 11:02:13 -04:00
|
|
|
if fetch(:sidekiq_default_hooks)
|
|
|
|
after 'deploy:starting', 'sidekiq:quiet'
|
|
|
|
after 'deploy:updated', 'sidekiq:stop'
|
|
|
|
after 'deploy:reverted', 'sidekiq:stop'
|
|
|
|
after 'deploy:published', 'sidekiq:start'
|
|
|
|
end
|
2013-10-28 11:01:36 -04:00
|
|
|
|
2013-10-15 14:11:44 -04:00
|
|
|
end
|