class Armada::Connection::HealthCheck

Attributes

endpoint[R]

Public Class Methods

new(host, port, endpoint = nil, delay = nil, retries = nil, gateway_host = nil, gateway_user = nil) click to toggle source
Calls superclass method
# File lib/armada/connection/health_check.rb, line 6
def initialize(host, port, endpoint = nil, delay = nil, retries = nil, gateway_host = nil, gateway_user = nil)
  super(host, port, gateway_host, gateway_user)
  @endpoint = endpoint ||= '/'
  @delay    = delay    ||= 1
  @retries  = retries  ||= 60
end

Public Instance Methods

healthy?() click to toggle source
# File lib/armada/connection/health_check.rb, line 32
def healthy?
  response = begin
    Excon.get("http://#{health_check_host}:#{health_check_port}#{@endpoint}")
  rescue Exception => e
    return false
  end

  return false unless response
  return true if response.status >= 200 && response.status < 300

  warn "Got HTTP status: #{response.status}"
  false
end
run() click to toggle source
# File lib/armada/connection/health_check.rb, line 17
def run
  info "Performing health check at - :#{@port}#{@endpoint}. Will retry every #{@delay} second(s) for #{@retries} times."
  1.upto(@retries) do |i|
    initialize_gateway!
    unless healthy?
      info "Still waiting for health check to pass at - :#{@port}#{@endpoint} endpoint..." if i % (@retries/10) == 0
      sleep(@delay)
    else
      info "Health check succeeded!"
      return true
    end
  end
  return false
end
to_s() click to toggle source
# File lib/armada/connection/health_check.rb, line 13
def to_s
  "#{@host}:#{@port}#{@endpoint}"
end

Private Instance Methods

health_check_host() click to toggle source
# File lib/armada/connection/health_check.rb, line 48
def health_check_host
  return "localhost" if @gateway
  return @host
end
health_check_port() click to toggle source
# File lib/armada/connection/health_check.rb, line 53
def health_check_port
  return @tunneled_port ||= port
end
info(message) click to toggle source
# File lib/armada/connection/health_check.rb, line 57
def info(message)
  Armada.ui.info "#{@host} -- #{message}"
end
warn(message) click to toggle source
# File lib/armada/connection/health_check.rb, line 61
def warn(message)
  Armada.ui.warn "#{@host} -- #{message}"
end