Sha256: f6c7814bdf3522084f9f58fe627b149b460e593e7ceff8b9f6caa1de3885eb2a

Contents?: true

Size: 1.59 KB

Versions: 29

Compression:

Stored size: 1.59 KB

Contents

module GovukHealthcheck
  class SidekiqQueueCheck
    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

    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

    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),
            }.select { |_, val| !(val.to_f.infinite? || val.to_f.nan?) },
          }
        end,
      }
    end

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

    def critical_threshold(queue:)
      raise "This method must be overriden to be the critical threshold."
    end

    def warning_threshold(queue:)
      raise "This method must be overriden to be the warning threshold."
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
govuk_app_config-2.2.0 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-2.1.2 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-2.1.1 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-2.1.0 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-2.0.3 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-2.0.2 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-2.0.1 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-2.0.0 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-1.20.2 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-1.20.1 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-1.20.0 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-1.19.0 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-1.18.1 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-1.17.0 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-1.16.3 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-1.16.1 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-1.16.0 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-1.15.1 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-1.15.0 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
govuk_app_config-1.14.0 lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb