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-4.8.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.7.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.6.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.5.1 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.5.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.4.2 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.4.1 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.4.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.3.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.2.1 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.2.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.1.1 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.1.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.99.1 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.0.3 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.0.2 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.0.1 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-4.0.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.99.0 lib/good_job/probe_server/healthcheck_middleware.rb
good_job-3.30.1 lib/good_job/probe_server/healthcheck_middleware.rb