Class: Startback::Web::HealthCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/startback/web/health_check.rb

Overview

Can be used to easily implement a HealthCheck web service inside a Startback application.

Examples:

# Returns a 204 with no body
run Startback::Web::HealthCheck.new

# Returns a 204 with no body
run Startback::Web::HealthCheck.new { nil }

# Returns a 200 with Ok in plain text
run Startback::Web::HealthCheck.new { "Ok" }

# Re-raises the exception
run Startback::Web::HealthCheck.new { raise "Something bad" }

Please note that this rack app is not 100% Rack compliant, since it raises any error that the block itself raises. This class aims at being backed up by a Shield and/or CatchAll middleware.

This class is not aimed at being subclassed.

Instance Method Summary collapse

Constructor Details

#initialize(&bl) ⇒ HealthCheck

Returns a new instance of HealthCheck.



29
30
31
# File 'lib/startback/web/health_check.rb', line 29

def initialize(&bl)
  @checker = bl
end

Instance Method Details

#call(env) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/startback/web/health_check.rb', line 33

def call(env)
  if debug_msg = check!(env)
    [ 200, { "Content-Type" => "text/plain" }, Array(debug_msg) ]
  else
    [ 204, {}, [] ]
  end
end