1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Add event when a process has a new heartbeat

This commit is contained in:
Mike Perham 2016-08-12 12:34:41 -07:00
parent b6de0bae6b
commit 008f1feff3
3 changed files with 18 additions and 3 deletions

View file

@ -28,6 +28,7 @@ module Sidekiq
startup: [], startup: [],
quiet: [], quiet: [],
shutdown: [], shutdown: [],
heartbeat: [],
}, },
dead_max_jobs: 10_000, dead_max_jobs: 10_000,
dead_timeout_in_seconds: 180 * 24 * 60 * 60 # 6 months dead_timeout_in_seconds: 180 * 24 * 60 * 60 # 6 months

View file

@ -94,15 +94,19 @@ module Sidekiq
end end
fails = procd = 0 fails = procd = 0
_, _, _, msg = Sidekiq.redis do |conn| _, exists, _, _, msg = Sidekiq.redis do |conn|
conn.multi do conn.multi do
conn.sadd('processes', key) conn.sadd('processes', key)
conn.exists(key)
conn.hmset(key, 'info', json, 'busy', Processor::WORKER_STATE.size, 'beat', Time.now.to_f, 'quiet', @done) conn.hmset(key, 'info', json, 'busy', Processor::WORKER_STATE.size, 'beat', Time.now.to_f, 'quiet', @done)
conn.expire(key, 60) conn.expire(key, 60)
conn.rpop("#{key}-signals") conn.rpop("#{key}-signals")
end end
end end
# first heartbeat or recovering from an outage and need to reestablish our heartbeat
fire_event(:heartbeat) if !exists
return unless msg return unless msg
if JVM_RESERVED_SIGNALS.include?(msg) if JVM_RESERVED_SIGNALS.include?(msg)

View file

@ -15,8 +15,6 @@ class TestLauncher < Sidekiq::Test
describe 'heartbeat' do describe 'heartbeat' do
before do before do
uow = Object.new
@mgr = new_manager(options) @mgr = new_manager(options)
@launcher = Sidekiq::Launcher.new(options) @launcher = Sidekiq::Launcher.new(options)
@launcher.manager = @mgr @launcher.manager = @mgr
@ -31,6 +29,18 @@ class TestLauncher < Sidekiq::Test
$0 = @proctitle $0 = @proctitle
end end
it 'fires new heartbeat events' do
i = 0
Sidekiq.on(:heartbeat) do
i += 1
end
assert_equal 0, i
@launcher.heartbeat('identity', heartbeat_data, Sidekiq.dump_json(heartbeat_data))
assert_equal 1, i
@launcher.heartbeat('identity', heartbeat_data, Sidekiq.dump_json(heartbeat_data))
assert_equal 1, i
end
describe 'when manager is active' do describe 'when manager is active' do
before do before do
Sidekiq::CLI::PROCTITLES << proc { "xyz" } Sidekiq::CLI::PROCTITLES << proc { "xyz" }