Module: Sidekiq::Datadog::Monitor::HeartbeatPatch

Defined in:
lib/sidekiq/datadog/monitor/heartbeat_patch.rb

Overview

Prior to Sidekiq 6.5.2 - there was no beat event that fired every couple seconds Following Module wraps original heartbeat method on Sidekiq::Launcher fires :beat lifecycle event

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.apply_heartbeat_patch(sidekiq_config) ⇒ Object



19
20
21
22
23
24
# File 'lib/sidekiq/datadog/monitor/heartbeat_patch.rb', line 19

def apply_heartbeat_patch(sidekiq_config)
  require 'sidekiq/launcher'

  sidekiq_config.options[:lifecycle_events][:beat] ||= []
  Sidekiq::Launcher.prepend(Sidekiq::Datadog::Monitor::HeartbeatPatch)
end

.needs_patching?(sidekiq_config) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/sidekiq/datadog/monitor/heartbeat_patch.rb', line 26

def needs_patching?(sidekiq_config)
  return false unless sidekiq_config.respond_to?(:options) # Unsupported config version
  return false unless sidekiq_config.options[:lifecycle_events] # No events exist, Sidekiq is too old
  return false if sidekiq_config.options[:lifecycle_events][:beat] # beat event exist - no need to patch

  true
end

Instance Method Details

#fire_beatObject



12
13
14
15
16
# File 'lib/sidekiq/datadog/monitor/heartbeat_patch.rb', line 12

def fire_beat
  return unless (listeners = Sidekiq.options[:lifecycle_events][:beat])

  listeners.each { |block| block.call }
end

#heartbeatObject



7
8
9
10
# File 'lib/sidekiq/datadog/monitor/heartbeat_patch.rb', line 7

def heartbeat
  super
  fire_beat
end