From 5de3ef43535148e304c07f80f479d68213c0d20b Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Thu, 7 Aug 2014 21:03:34 -0700 Subject: [PATCH] Send the full process info on each heartbeat so transient timeouts don't lead to a process disappearing in Busy, fixes #1884 --- Changes.md | 2 ++ lib/sidekiq/launcher.rb | 13 +++++-------- lib/sidekiq/manager.rb | 13 +++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Changes.md b/Changes.md index c6d53a17..2acfa959 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,8 @@ 3.2.2 ----------- +- Fix issue which could cause Sidekiq workers to disappear from the Busy + tab while still being active [#1884] - Add "Back to App" button in Web UI. You can set the button link via `Sidekiq::Web.app_url = 'http://www.mysite.com'` [#1875, seuros] - Add process tag (`-g tag`) to the Busy page so you can differentiate processes at a glance. [seuros, #1878] diff --git a/lib/sidekiq/launcher.rb b/lib/sidekiq/launcher.rb index 9beb1799..413b7bd9 100644 --- a/lib/sidekiq/launcher.rb +++ b/lib/sidekiq/launcher.rb @@ -71,14 +71,10 @@ module Sidekiq 'queues' => @options[:queues].uniq, 'labels' => Sidekiq.options[:labels], } - Sidekiq.redis do |conn| - conn.multi do - conn.sadd('processes', key) - conn.hset(key, 'info', Sidekiq.dump_json(data)) - conn.expire(key, 60) - end - end - manager.heartbeat(key, data) + # this data doesn't change so dump it to a string + # now so we don't need to dump it every heartbeat. + json = Sidekiq.dump_json(data) + manager.heartbeat(key, data, json) end def stop_heartbeat @@ -89,5 +85,6 @@ module Sidekiq end end end + end end diff --git a/lib/sidekiq/manager.rb b/lib/sidekiq/manager.rb index 5723c190..fea30822 100644 --- a/lib/sidekiq/manager.rb +++ b/lib/sidekiq/manager.rb @@ -132,26 +132,27 @@ module Sidekiq @threads[proxy_id] = thr end - def heartbeat(key, data) + def heartbeat(key, data, json) 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(' ') - ❤(key) + ❤(key, json) after(5) do - heartbeat(key, data) + heartbeat(key, data, json) end end private - def ❤(key) + def ❤(key, json) begin - _, _, msg = Sidekiq.redis do |conn| + _, _, _, msg = Sidekiq.redis do |conn| conn.multi do - conn.hmset(key, 'busy', @busy.size, 'beat', Time.now.to_f) + conn.sadd('processes', key) + conn.hmset(key, 'info', json, 'busy', @busy.size, 'beat', Time.now.to_f) conn.expire(key, 60) conn.rpop("#{key}-signals") end