Sha256: fcd5e522db9f79ffa54d414736f461265422b4dcb4bc14b2a9b77c15c544dac8

Contents?: true

Size: 879 Bytes

Versions: 38

Compression:

Stored size: 879 Bytes

Contents

# frozen_string_literal: true

module GoodJob
  class ProbeServer
    class HealthcheckMiddleware
      def initialize(app)
        @app = app
      end

      def call(env)
        case Rack::Request.new(env).path
        when '/', '/status'
          [200, {}, ["OK"]]
        when '/status/started'
          started = GoodJob::Scheduler.instances.any? && GoodJob::Scheduler.instances.all?(&:running?)
          started ? [200, {}, ["Started"]] : [503, {}, ["Not started"]]
        when '/status/connected'
          connected = GoodJob::Scheduler.instances.any? && GoodJob::Scheduler.instances.all?(&:running?) &&
                      GoodJob::Notifier.instances.any? && GoodJob::Notifier.instances.all?(&:connected?)
          connected ? [200, {}, ["Connected"]] : [503, {}, ["Not connected"]]
        else
          @app.call(env)
        end
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
good_job-3.30.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.29.5 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.29.4 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.29.3 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.28.2 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.28.1 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.28.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.27.4 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.27.3 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.27.2 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.27.1 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.27.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.26.2 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.26.1 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.26.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.25.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.24.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.23.0 lib/good_job/probe_server/healthcheck_middleware.rb