Class: ElasticBeans::Rack::HealthCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_beans/rack/health_check.rb

Overview

A middleware that returns 200 OK to aws-sqsd‘s health check, which does not support HTTPS. Load it in your Rails application so non-webserver environments are considered healthy.

Only accepts localhost requests to GET the root path.

Constant Summary collapse

SUCCESS =
['200', {'Content-type' => 'text/plain'}, [""]]

Instance Method Summary collapse

Constructor Details

#initialize(app, args = {}) ⇒ HealthCheck

Returns a new instance of HealthCheck.



13
14
15
16
# File 'lib/elastic_beans/rack/health_check.rb', line 13

def initialize(app, args={})
  @app = app
  @logger = args[:logger] || Logger.new("/dev/null")
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/elastic_beans/rack/health_check.rb', line 18

def call(env)
  request = ActionDispatch::Request.new(env)
  if enabled? && health_request?(request)
    logger.debug { "[elastic_beans] Healthy response to local client" }
    return SUCCESS
  end

  logger.debug { "[elastic_beans] skipped health request: #{request.path}" }
  app.call(env)
end