Class: Rack::HaproxyStatus::Endpoint

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

Constant Summary collapse

InvalidStatus =
Class.new(StandardError)
VALID_STATES =
%w(on off)

Instance Method Summary collapse

Constructor Details

#initialize(path:, io: File) ⇒ Endpoint

Returns a new instance of Endpoint.



10
11
12
13
# File 'lib/rack/haproxy_status.rb', line 10

def initialize(path:, io: File)
  @path = path
  @io = io
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/rack/haproxy_status.rb', line 15

def call(env)
  if balancer_member?
    [200, {'Content-Type' => 'application/json'}, ['{"status": "ok", "member": true}']]
  else
    [503, {'Content-Type' => 'application/json'}, ['{"status": "ok", "member": false}']]
  end
rescue InvalidStatus
  [500, {'Content-Type' => 'application/json'}, ['{"status": "unknown status"}']]
end