Class: Liveness::Status
- Inherits:
-
Object
- Object
- Liveness::Status
- Defined in:
- lib/liveness/status.rb
Overview
The status endpoint to return check status
Constant Summary collapse
- HEADERS =
{ 'Content-Type' => 'application/json' }.freeze
- FORBIDDEN_MESSAGE =
{ message: 'access denied' }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #forbidden ⇒ Rack::Response
- #initialize(env, config: Liveness.config) ⇒ Liveness::Status constructor
-
#live? ⇒ Boolean
The Liveness status.
-
#metrics ⇒ Hash
The depend services status.
- #response ⇒ Rack::Response
Constructor Details
#initialize(env, config: Liveness.config) ⇒ Liveness::Status
24 25 26 27 28 |
# File 'lib/liveness/status.rb', line 24 def initialize(env, config: Liveness.config) @env = env @request = Rack::Request.new(env) @config = config end |
Class Method Details
.call(env) ⇒ Object
10 11 12 |
# File 'lib/liveness/status.rb', line 10 def call(env) new(env).response end |
Instance Method Details
#forbidden ⇒ Rack::Response
70 71 72 73 74 |
# File 'lib/liveness/status.rb', line 70 def forbidden [ 403, HEADERS, [FORBIDDEN_MESSAGE.to_json] ] end |
#live? ⇒ Boolean
The Liveness status
46 47 48 49 50 51 |
# File 'lib/liveness/status.rb', line 46 def live? metrics .values .map { |service| service[:status] == 'ok' } .reduce(true, :&) end |
#metrics ⇒ Hash
The depend services status
35 36 37 38 39 |
# File 'lib/liveness/status.rb', line 35 def metrics @metrics ||= @config.dependencies.map do |dependency| Thread.new { [dependency.name, dependency.status] } end.map(&:value).to_h end |
#response ⇒ Rack::Response
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/liveness/status.rb', line 56 def response access = Access.new(@request, config: @config) return forbidden unless access.allowed? [ live? ? 200 : 503, HEADERS, [metrics.to_json] ] end |