Class: Bamboo::Service::HealthCheckClient

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/bamboo/server.rb

Overview

Talks to the service in order to find out about the current health of the service. Since bamboo does not have a health check API, we just hit the REST endpoint /rest/api/latest/info and check http return code

Constant Summary collapse

NOT_RUNNING_MSG =
'Bamboo service is not running, yet. Last reported status is: %s'
CONFIGURATION_BROKEN_MSG =
'Bamboo service reached state %s from which it cannot recover from without user intervention. Reported error is: %s.'

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ HealthCheckClient

Returns a new instance of HealthCheckClient.



99
100
101
# File 'lib/puppet_x/bamboo/server.rb', line 99

def initialize(configuration)
  @bamboo = Bamboo::Rest.new(configuration, configuration[:bamboo_base_url])
end

Instance Method Details

#check_healthObject

Returns the health status of the service.



105
106
107
108
109
110
111
112
113
114
# File 'lib/puppet_x/bamboo/server.rb', line 105

def check_health
  response = @bamboo.make_request('/rest/api/latest/info', 'get') do |req|
    req['Accept-Encoding'] = 'application/json'
  end
  case response.code
    when '200' then Service::Status.running
    when '500' then Service::Status.broken(response.to_s)
    else Service::Status.not_running(NOT_RUNNING_MSG % response.to_s)
  end
end