From 473de4da8f1da83049da6b672945597aa7d6d494 Mon Sep 17 00:00:00 2001 From: Dmitry Krasnoukhov Date: Mon, 14 Apr 2014 01:30:25 +0300 Subject: [PATCH] Indicate in procline that manager have stopped --- lib/sidekiq/manager.rb | 5 +++-- test/test_manager.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/sidekiq/manager.rb b/lib/sidekiq/manager.rb index 3ce9223c..c0c50d25 100644 --- a/lib/sidekiq/manager.rb +++ b/lib/sidekiq/manager.rb @@ -133,13 +133,14 @@ module Sidekiq end def heartbeat(key, data) - return if stopped? - proctitle = ['sidekiq', Sidekiq::VERSION] proctitle << data['tag'] unless data['tag'].empty? proctitle << "[#{@busy.size} of #{data['concurrency']} busy]" proctitle << 'stopping' if stopped? $0 = proctitle.join(' ') + + return if stopped? + ❤(key) after(5) do heartbeat(key, data) diff --git a/test/test_manager.rb b/test/test_manager.rb index ccf21c28..6d78af02 100644 --- a/test/test_manager.rb +++ b/test/test_manager.rb @@ -1,5 +1,6 @@ require 'helper' require 'sidekiq/manager' +require 'sidekiq/util' class TestManager < Sidekiq::Test @@ -77,9 +78,36 @@ class TestManager < Sidekiq::Test fetcher.verify end + describe 'heartbeat' do + describe 'proctitle' do + it 'sets useful info' do + mgr = Sidekiq::Manager.new(options) + mgr.heartbeat('identity', heartbeat_data) + + proctitle = $0 + assert_equal $0, "sidekiq #{Sidekiq::VERSION} myapp [0 of 3 busy]" + $0 = proctitle + end + + it 'indicates when stopped' do + mgr = Sidekiq::Manager.new(options) + mgr.stop + mgr.heartbeat('identity', heartbeat_data) + + proctitle = $0 + assert_equal $0, "sidekiq #{Sidekiq::VERSION} myapp [0 of 3 busy] stopping" + $0 = proctitle + end + end + end + def options { :concurrency => 3, :queues => ['default'] } end + + def heartbeat_data + { 'concurrency' => 3, 'tag' => 'myapp' } + end end end