Sha256: 8c0bb2342a25a0b68b751d18c8bb00e8baafa23bac9756a21d2952cd4258ce4e

Contents?: true

Size: 662 Bytes

Versions: 2

Compression:

Stored size: 662 Bytes

Contents

# frozen_string_literal: true

module HttpHealthCheck
  module Probes
    class Sidekiq
      include ::HttpHealthCheck::Probe

      TTL_SEC = 3
      MAGIC_NUMBER = 42

      def initialize(sidekiq: ::Sidekiq)
        @sidekiq_module = sidekiq
      end

      def probe(_env)
        @sidekiq_module.redis do |conn|
          conn.call('SET', meta[:redis_key], MAGIC_NUMBER, 'EX', TTL_SEC)
          probe_ok
        end
      end

      def meta
        @meta ||= { redis_key: redis_key }
      end

      private

      def redis_key
        @redis_key ||= ['sidekiq-healthcheck', ::Socket.gethostname, ::Process.pid].join('::')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
http_health_check-1.0.0 lib/http_health_check/probes/sidekiq.rb
http_health_check-0.5.0 lib/http_health_check/probes/sidekiq.rb