Class: Sidekiq::HeartbeatMonitor::Worker

Inherits:
Object
  • Object
show all
Includes:
Util, Worker
Defined in:
lib/sidekiq/heartbeat_monitor/worker.rb

Instance Method Summary collapse

Methods included from Util

#format_time_str

Instance Method Details

#perform(queue_name) ⇒ Object

Runs every x seconds and ensures that the time between jobs is consistent and

Parameters:

  • queue_name (String)

    Name of the queue that this heartbeat is running on.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sidekiq/heartbeat_monitor/worker.rb', line 12

def perform(queue_name)
  Sidekiq.redis do |redis|
    q = Sidekiq::Queue.all.find{ |q| q.name.to_s == queue_name.to_s }
    queue_config = Sidekiq::HeartbeatMonitor.config(q)

    key = "Sidekiq:HeartbeatMonitor:Worker-#{queue_name}.enqueued_at"
    enqueued_at = redis.get(key).to_i

    return if enqueued_at < 1577997505 # Enqueued before Jan 2, 2020 when this code was written

    time_since_enqueued = Time.now.to_i - enqueued_at

    if time_since_enqueued > queue_config.max_heartbeat_delay
      queue_config.send_slowed_down_alert!("⚠️ _#{queue_name}_ queue took #{format_time_str(time_since_enqueued)} to reach job.", q)
    end

    redis.del(key)
  end
end