class Minke::Docker::HealthCheck

HealthCheck checks health of a running container

Public Class Methods

new(logger, count=nil, pause=nil) click to toggle source
# File lib/minke/docker/health_check.rb, line 7
def initialize logger, count=nil, pause=nil
  @count = count ||= 180
  @pause = pause ||= 1
  @successes = 2
  @logger = logger
end

Public Instance Methods

wait_for_HTTPOK(url) click to toggle source

waits until a 200 response is received from the given url

# File lib/minke/docker/health_check.rb, line 16
def wait_for_HTTPOK url
  @logger.debug "Waiting for server #{url} to start #{@count} attempts remaining"

  begin
    response = RestClient.send('get', url)
  rescue
    @logger.debug 'Invalid response from server'
  end

  check_response response, url
end

Private Instance Methods

check_failed(url) click to toggle source
# File lib/minke/docker/health_check.rb, line 37
def check_failed url
  @count -= 1
  sleep @pause

  if @count > 0
    wait_for_HTTPOK url
  else
    @logger.error "Server: #{url} failed health check"
    raise 'Server failed to start'
  end
end
check_response(response, url) click to toggle source
# File lib/minke/docker/health_check.rb, line 29
def check_response response, url
  if response == nil || !response.code.to_i == 200
    check_failed url
  else
    check_success url
  end
end
check_success(url) click to toggle source
# File lib/minke/docker/health_check.rb, line 49
def check_success url
  if @successes > 0 
    @logger.debug "Server: #{url} passed health check, #{@successes} checks to go..."

    @successes -= 1
    sleep @pause
    wait_for_HTTPOK url
  else
    @logger.debug "Server: #{url} healthy"
  end
end