Class: RailsHealthChecks::Checks::SidekiqCheck

Inherits:
RailsHealthChecks::Check show all
Defined in:
lib/rails_health_checks/checks/sidekiq_check.rb

Instance Attribute Summary

Attributes inherited from RailsHealthChecks::Check

#latency_ms, #message, #status

Instance Method Summary collapse

Constructor Details

#initialize(queue_size: nil) ⇒ SidekiqCheck

Returns a new instance of SidekiqCheck.



6
7
8
9
10
11
12
# File 'lib/rails_health_checks/checks/sidekiq_check.rb', line 6

def initialize(queue_size: nil)
  unless defined?(::Sidekiq)
    raise LoadError, "Sidekiq is not installed. Add `gem 'sidekiq'` to your Gemfile to use the :sidekiq check."
  end

  @queue_size = queue_size
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rails_health_checks/checks/sidekiq_check.rb', line 14

def call
  measure { ::Sidekiq.redis { |conn| conn.ping } }

  if @queue_size
    depth = ::Sidekiq::Queue.all.sum(&:size)
    return warn_with("queue depth #{depth} exceeds threshold #{@queue_size}") if depth > @queue_size
  end

  pass
rescue StandardError => e
  fail_with(e.message)
end