From 6cffbb9adbed0c6ce78408743fabb44adeac1b80 Mon Sep 17 00:00:00 2001 From: Bruno Zanchet Date: Fri, 20 Apr 2012 14:12:21 -0300 Subject: [PATCH 1/4] do not halt deployment if no servers are going to run sidekiq workers --- lib/sidekiq/capistrano.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/sidekiq/capistrano.rb b/lib/sidekiq/capistrano.rb index dce344c9..9b8d01ed 100644 --- a/lib/sidekiq/capistrano.rb +++ b/lib/sidekiq/capistrano.rb @@ -10,23 +10,23 @@ Capistrano::Configuration.instance.load do namespace :sidekiq do desc "Quiet sidekiq (stop accepting new work)" - task :quiet, :roles => lambda { fetch(:sidekiq_role) } do + task :quiet, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do run "cd #{current_path} && if [ -f #{current_path}/tmp/pids/sidekiq.pid ]; then #{fetch(:bundle_cmd, "bundle")} exec sidekiqctl quiet #{current_path}/tmp/pids/sidekiq.pid ; fi" end desc "Stop sidekiq" - task :stop, :roles => lambda { fetch(:sidekiq_role) } do + task :stop, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do run "cd #{current_path} && if [ -f #{current_path}/tmp/pids/sidekiq.pid ]; then #{fetch(:bundle_cmd, "bundle")} exec sidekiqctl stop #{current_path}/tmp/pids/sidekiq.pid #{fetch :sidekiq_timeout} ; fi" end desc "Start sidekiq" - task :start, :roles => lambda { fetch(:sidekiq_role) } do + task :start, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do rails_env = fetch(:rails_env, "production") run "cd #{current_path} ; nohup #{fetch(:bundle_cmd, "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 &", :pty => false end desc "Restart sidekiq" - task :restart, :roles => lambda { fetch(:sidekiq_role) } do + task :restart, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do stop start end From 3c6281490b651e4ecd8584111c3880b2666edc20 Mon Sep 17 00:00:00 2001 From: Andrew Selder Date: Fri, 18 May 2012 15:04:25 -0700 Subject: [PATCH 2/4] Use inject rather than sum to compute backlog size Sum is not a built in method on Enumerable, it is an extension defined in ActiveSupport. This allows a more generic and universal use of the web ui. --- web/views/index.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/views/index.slim b/web/views/index.slim index f04a42d9..a4c0d72d 100644 --- a/web/views/index.slim +++ b/web/views/index.slim @@ -5,7 +5,7 @@ p Failed: #{failed} p Busy Workers: #{workers.size} p Retries Pending: #{retry_count} - p Queue Backlog: #{queues.map{|q,size| size}.sum} + p Queue Backlog: #{queues.values.inject(0){|memo, val| memo + val}} .tabbable ul.nav.nav-tabs From 7be31028656c917b5a888838f2d27c05d1d154aa Mon Sep 17 00:00:00 2001 From: Daniel Azuma Date: Mon, 21 May 2012 11:13:20 -0700 Subject: [PATCH 3/4] Gracefully handle receipt of multiple termination signals --- lib/sidekiq/cli.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/sidekiq/cli.rb b/lib/sidekiq/cli.rb index 718ca34d..ecd9e515 100644 --- a/lib/sidekiq/cli.rb +++ b/lib/sidekiq/cli.rb @@ -1,12 +1,12 @@ trap 'INT' do # Handle Ctrl-C in JRuby like MRI # http://jira.codehaus.org/browse/JRUBY-4637 - Thread.main.raise Interrupt + Sidekiq::CLI.instance.interrupt end trap 'TERM' do # Heroku sends TERM and then waits 10 seconds for process to exit. - Thread.main.raise Interrupt + Sidekiq::CLI.instance.interrupt end trap 'USR1' do @@ -43,6 +43,8 @@ module Sidekiq def initialize @code = nil + @interrupt_mutex = Mutex.new + @interrupted = false end def parse(args=ARGV) @@ -80,6 +82,15 @@ module Sidekiq end end + def interrupt + @interrupt_mutex.synchronize do + unless @interrupted + @interrupted = true + Thread.main.raise Interrupt + end + end + end + private def die(code) From f527ed9a0e0706773e2bcc9f55db61f97159186b Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Tue, 22 May 2012 07:16:08 -0700 Subject: [PATCH 4/4] Missing method values, fixes #208 --- lib/sidekiq/web.rb | 4 ++++ web/views/index.slim | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/sidekiq/web.rb b/lib/sidekiq/web.rb index 8efd5593..a9e519ae 100644 --- a/lib/sidekiq/web.rb +++ b/lib/sidekiq/web.rb @@ -76,6 +76,10 @@ module Sidekiq end end + def backlog + queues.map {|name, size| size }.inject(0) {|memo, val| memo + val } + end + def retries_with_score(score) Sidekiq.redis do |conn| results = conn.zrangebyscore('retry', score, score) diff --git a/web/views/index.slim b/web/views/index.slim index a4c0d72d..85882d80 100644 --- a/web/views/index.slim +++ b/web/views/index.slim @@ -5,7 +5,7 @@ p Failed: #{failed} p Busy Workers: #{workers.size} p Retries Pending: #{retry_count} - p Queue Backlog: #{queues.values.inject(0){|memo, val| memo + val}} + p Queue Backlog: #{backlog} .tabbable ul.nav.nav-tabs