mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Merge pull request #3108 from mperham/heartbeat_event
Add event when a process has a new heartbeat
This commit is contained in:
commit
e514aae969
4 changed files with 19 additions and 4 deletions
|
@ -28,6 +28,7 @@ module Sidekiq
|
|||
startup: [],
|
||||
quiet: [],
|
||||
shutdown: [],
|
||||
heartbeat: [],
|
||||
},
|
||||
dead_max_jobs: 10_000,
|
||||
dead_timeout_in_seconds: 180 * 24 * 60 * 60 # 6 months
|
||||
|
|
|
@ -94,15 +94,19 @@ module Sidekiq
|
|||
end
|
||||
fails = procd = 0
|
||||
|
||||
_, _, _, msg = Sidekiq.redis do |conn|
|
||||
_, exists, _, _, msg = Sidekiq.redis do |conn|
|
||||
conn.multi do
|
||||
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.expire(key, 60)
|
||||
conn.rpop("#{key}-signals")
|
||||
end
|
||||
end
|
||||
|
||||
# first heartbeat or recovering from an outage and need to reestablish our heartbeat
|
||||
fire_event(:heartbeat) if !exists
|
||||
|
||||
return unless msg
|
||||
|
||||
if JVM_RESERVED_SIGNALS.include?(msg)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
module Sidekiq
|
||||
VERSION = "4.1.4"
|
||||
VERSION = "4.1.5"
|
||||
end
|
||||
|
|
|
@ -15,8 +15,6 @@ class TestLauncher < Sidekiq::Test
|
|||
|
||||
describe 'heartbeat' do
|
||||
before do
|
||||
uow = Object.new
|
||||
|
||||
@mgr = new_manager(options)
|
||||
@launcher = Sidekiq::Launcher.new(options)
|
||||
@launcher.manager = @mgr
|
||||
|
@ -31,6 +29,18 @@ class TestLauncher < Sidekiq::Test
|
|||
$0 = @proctitle
|
||||
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
|
||||
before do
|
||||
Sidekiq::CLI::PROCTITLES << proc { "xyz" }
|
||||
|
|
Loading…
Reference in a new issue