Class: GovukHealthcheck::SidekiqQueueCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb

Direct Known Subclasses

SidekiqQueueLatencyCheck

Instance Method Summary collapse

Instance Method Details

#critical_threshold(queue:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



54
55
56
# File 'lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb', line 54

def critical_threshold(queue:) # rubocop:disable Lint/UnusedMethodArgument
  raise "This method must be overriden to be the critical threshold."
end

#detailsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb', line 36

def details
  {
    queues: queues.each_with_object({}) do |(name, value), hash|
      hash[name] = {
        value: value,
        thresholds: {
          critical: critical_threshold(queue: name),
          warning: warning_threshold(queue: name),
        }.reject { |_, val| val.to_f.infinite? || val.to_f.nan? },
      }
    end,
  }
end

#messageObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb', line 15

def message
  messages = queues.map do |name, value|
    critical = critical_threshold(queue: name)
    warning = warning_threshold(queue: name)

    if value >= critical
      "#{name} (#{value}) is above the critical threshold (#{critical})"
    elsif value >= warning
      "#{name} (#{value}) is above the warning threshold (#{warning})"
    end
  end

  messages = messages.compact

  if messages.empty?
    "all queues are below the critical and warning thresholds"
  else
    messages.join("\n")
  end
end

#queuesObject



50
51
52
# File 'lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb', line 50

def queues
  raise "This method must be overriden to be a hash of queue names and data."
end

#statusObject



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb', line 3

def status
  queues.each do |name, value|
    if value >= critical_threshold(queue: name)
      return :critical
    elsif value >= warning_threshold(queue: name)
      return :warning
    end
  end

  :ok
end

#warning_threshold(queue:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



58
59
60
# File 'lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb', line 58

def warning_threshold(queue:) # rubocop:disable Lint/UnusedMethodArgument
  raise "This method must be overriden to be the warning threshold."
end