Class: GoodJob::ProbeServer::HealthcheckMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/good_job/probe_server/healthcheck_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ HealthcheckMiddleware

Returns a new instance of HealthcheckMiddleware.



6
7
8
# File 'lib/good_job/probe_server/healthcheck_middleware.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/good_job/probe_server/healthcheck_middleware.rb', line 10

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