mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
80 lines
2.4 KiB
Ruby
80 lines
2.4 KiB
Ruby
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
|
|
for_each_process do |pid_file, idx|
|
|
execute "if [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then cd #{fetch(:current_path)} && #{fetch(:sidekiqctl_cmd)} quiet #{pid_file} ; else echo 'Sidekiq is not running'; fi"
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
desc "Stop sidekiq"
|
|
task :stop do
|
|
on roles fetch(:sidekiq_role) do
|
|
for_each_process do |pid_file, idx|
|
|
execute "if [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then cd #{fetch(:current_path)} #{fetch(:sidekiqctl_cmd)} stop #{pid_file} #{fetch :sidekiq_timeout} ; else echo 'Sidekiq is not running'; fi"
|
|
end
|
|
end
|
|
end
|
|
|
|
desc "Start sidekiq"
|
|
task :start do
|
|
on roles fetch(:sidekiq_role) do
|
|
rails_env = fetch(:rails_env, "production")
|
|
for_each_process do |pid_file, idx|
|
|
execute "cd #{current_path} ; nohup #{fetch(:sidekiq_cmd)} -e #{rails_env} -C #{current_path}/config/sidekiq.yml -i #{idx} -P #{pid_file} >> #{current_path}/log/sidekiq.log 2>&1 &"
|
|
end
|
|
end
|
|
end
|
|
|
|
desc "Restart sidekiq"
|
|
task :restart do
|
|
on roles fetch(:sidekiq_role) do
|
|
stop
|
|
start
|
|
end
|
|
end
|
|
|
|
before 'deploy:updating', 'sidekiq:quiet'
|
|
after 'deploy:published', 'sidekiq:restart'
|
|
|
|
end
|
|
|
|
namespace :load do
|
|
task :defaults do
|
|
set :sidekiq_default_hooks, ->{ true }
|
|
set :sidekiq_cmd, ->{ :sidekiq }
|
|
set :sidekiqctl_cmd, ->{ :sidekiqctl }
|
|
set :sidekiq_timeout, ->{ 10 }
|
|
set :sidekiq_role, ->{ :app }
|
|
set :sidekiq_pid, ->{ "#{fetch :shared_path}/tmp/pids/sidekiq.pid" }
|
|
set :sidekiq_processes, ->{ 1 }
|
|
end
|
|
end
|
|
|
|
|
|
__END__
|
|
desc "Update application's crontab entries using Whenever"
|
|
task :update_crontab do
|
|
on roles fetch(:whenever_roles) do
|
|
within release_path do
|
|
execute fetch(:whenever_command), fetch(:whenever_update_flags)
|
|
end
|
|
end
|
|
end
|
|
|
|
desc "Clear application's crontab entries using Whenever"
|
|
task :clear_crontab do
|
|
on roles fetch(:whenever_roles) do
|
|
within release_path do
|
|
execute %{#{fetch(:whenever_command)} #{fetch(:whenever_clear_flags)}}
|
|
end
|
|
end
|
|
end
|