From 574588861839a80920e681e0e9d9c52311bf8875 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Thu, 20 Aug 2015 12:06:43 +0100 Subject: [PATCH] depend on recent version of Sidekiq rename tasks to .rake --- capistrano-sidekiq.gemspec | 2 +- lib/capistrano/sidekiq.rb | 2 +- lib/capistrano/sidekiq/monit.rb | 2 +- .../tasks/{monit.cap => monit.rake} | 67 ++++++++----------- .../tasks/{sidekiq.cap => sidekiq.rake} | 3 - 5 files changed, 30 insertions(+), 46 deletions(-) rename lib/capistrano/tasks/{monit.cap => monit.rake} (58%) rename lib/capistrano/tasks/{sidekiq.cap => sidekiq.rake} (98%) diff --git a/capistrano-sidekiq.gemspec b/capistrano-sidekiq.gemspec index d24dde8..86d870e 100644 --- a/capistrano-sidekiq.gemspec +++ b/capistrano-sidekiq.gemspec @@ -18,5 +18,5 @@ Gem::Specification.new do |spec| spec.require_paths = ['lib'] spec.add_dependency 'capistrano' - spec.add_dependency 'sidekiq' + spec.add_dependency 'sidekiq', '>= 3.4' end diff --git a/lib/capistrano/sidekiq.rb b/lib/capistrano/sidekiq.rb index 424c52e..7765683 100644 --- a/lib/capistrano/sidekiq.rb +++ b/lib/capistrano/sidekiq.rb @@ -1,5 +1,5 @@ if Gem::Specification.find_by_name('capistrano').version >= Gem::Version.new('3.0.0') - load File.expand_path('../tasks/sidekiq.cap', __FILE__) + load File.expand_path('../tasks/sidekiq.rake', __FILE__) else require_relative 'tasks/capistrano2' end diff --git a/lib/capistrano/sidekiq/monit.rb b/lib/capistrano/sidekiq/monit.rb index 9ef6457..17918e5 100644 --- a/lib/capistrano/sidekiq/monit.rb +++ b/lib/capistrano/sidekiq/monit.rb @@ -1,2 +1,2 @@ # load monit tasks -load File.expand_path('../../tasks/monit.cap', __FILE__) \ No newline at end of file +load File.expand_path('../../tasks/monit.rake', __FILE__) \ No newline at end of file diff --git a/lib/capistrano/tasks/monit.cap b/lib/capistrano/tasks/monit.rake similarity index 58% rename from lib/capistrano/tasks/monit.cap rename to lib/capistrano/tasks/monit.rake index 5c3ab31..0655366 100644 --- a/lib/capistrano/tasks/monit.cap +++ b/lib/capistrano/tasks/monit.rake @@ -1,9 +1,10 @@ namespace :load do task :defaults do - set :sidekiq_monit_conf_dir, -> { '/etc/monit/conf.d' } - set :sidekiq_monit_use_sudo, -> { true } - set :monit_bin, -> { '/usr/bin/monit' } - set :sidekiq_monit_default_hooks, -> { true } + set :sidekiq_monit_conf_dir, '/etc/monit/conf.d' + set :sidekiq_monit_use_sudo, true + set :monit_bin, '/usr/bin/monit' + set :sidekiq_monit_default_hooks, true + set :sidekiq_monit_templates_path, 'config/deploy/templates' end end @@ -38,15 +39,13 @@ namespace :sidekiq do desc 'Monitor Sidekiq monit-service' task :monitor do - Array(fetch(:sidekiq_role)).each do |role| - on roles(role) do - sidekiq_processes(role).times do |idx| - begin - sudo_if_needed "#{fetch(:monit_bin)} monitor #{sidekiq_service_name(idx)}" - rescue - invoke 'sidekiq:monit:config' - sudo_if_needed "#{fetch(:monit_bin)} monitor #{sidekiq_service_name(idx)}" - end + on roles(fetch(:sidekiq_role)) do + fetch(:sidekiq_processes).times do |idx| + begin + sudo_if_needed "#{fetch(:monit_bin)} monitor #{sidekiq_service_name(idx)}" + rescue + invoke 'sidekiq:monit:config' + sudo_if_needed "#{fetch(:monit_bin)} monitor #{sidekiq_service_name(idx)}" end end end @@ -54,14 +53,12 @@ namespace :sidekiq do desc 'Unmonitor Sidekiq monit-service' task :unmonitor do - Array(fetch(:sidekiq_role)).each do |role| - on roles(role) do - sidekiq_processes(role).times do |idx| - begin - sudo_if_needed "#{fetch(:monit_bin)} unmonitor #{sidekiq_service_name(idx)}" - rescue - # no worries here - end + on roles(fetch(:sidekiq_role)) do + fetch(:sidekiq_processes).times do |idx| + begin + sudo_if_needed "#{fetch(:monit_bin)} unmonitor #{sidekiq_service_name(idx)}" + rescue + # no worries here end end end @@ -69,33 +66,27 @@ namespace :sidekiq do desc 'Start Sidekiq monit-service' task :start do - Array(fetch(:sidekiq_role)).each do |role| - on roles(role) do - sidekiq_processes(role).times do |idx| - sudo_if_needed "#{fetch(:monit_bin)} start #{sidekiq_service_name(idx)}" - end + on roles(fetch(:sidekiq_role)) do + fetch(:sidekiq_processes).times do |idx| + sudo_if_needed "#{fetch(:monit_bin)} start #{sidekiq_service_name(idx)}" end end end desc 'Stop Sidekiq monit-service' task :stop do - Array(fetch(:sidekiq_role)).each do |role| - on roles(role) do - sidekiq_processes(role).times do |idx| - sudo_if_needed "#{fetch(:monit_bin)} stop #{sidekiq_service_name(idx)}" - end + on roles(fetch(:sidekiq_role)) do + fetch(:sidekiq_processes).times do |idx| + sudo_if_needed "#{fetch(:monit_bin)} stop #{sidekiq_service_name(idx)}" end end end desc 'Restart Sidekiq monit-service' task :restart do - Array(fetch(:sidekiq_role)).each do |role| - on roles(role) do - sidekiq_processes(role).times do |idx| - sudo_if_needed"#{fetch(:monit_bin)} restart #{sidekiq_service_name(idx)}" - end + on roles(fetch(:sidekiq_role)) do + fetch(:sidekiq_processes).times do |idx| + sudo_if_needed"#{fetch(:monit_bin)} restart #{sidekiq_service_name(idx)}" end end end @@ -136,9 +127,5 @@ namespace :sidekiq do fetch(:sidekiq_monit_use_sudo) end - def sidekiq_processes(role) - fetch(:"#{ role }_processes") || fetch(:sidekiq_processes) - end - end end diff --git a/lib/capistrano/tasks/sidekiq.cap b/lib/capistrano/tasks/sidekiq.rake similarity index 98% rename from lib/capistrano/tasks/sidekiq.cap rename to lib/capistrano/tasks/sidekiq.rake index 6ac4724..4ec4b2a 100644 --- a/lib/capistrano/tasks/sidekiq.cap +++ b/lib/capistrano/tasks/sidekiq.rake @@ -1,6 +1,5 @@ namespace :load do task :defaults do - set :sidekiq_user, nil set :sidekiq_default_hooks, -> { true } set :sidekiq_pid, -> { File.join(shared_path, 'tmp', 'pids', 'sidekiq.pid') } @@ -13,8 +12,6 @@ namespace :load do # Rbenv and RVM integration set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w(sidekiq sidekiqctl)) set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w(sidekiq sidekiqctl)) - - set :sidekiq_monit_templates_path, -> { 'config/deploy/templates' } end end