Class: Armada::Connection::HealthCheck
- Defined in:
- lib/armada/connection/health_check.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Attributes inherited from Remote
Instance Method Summary collapse
- #healthy? ⇒ Boolean
-
#initialize(host, port, endpoint = nil, delay = nil, retries = nil, gateway_host = nil, gateway_user = nil) ⇒ HealthCheck
constructor
A new instance of HealthCheck.
- #run ⇒ Object
- #to_s ⇒ Object
Methods inherited from Remote
Constructor Details
#initialize(host, port, endpoint = nil, delay = nil, retries = nil, gateway_host = nil, gateway_user = nil) ⇒ HealthCheck
Returns a new instance of HealthCheck.
6 7 8 9 10 11 |
# 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 |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
5 6 7 |
# File 'lib/armada/connection/health_check.rb', line 5 def endpoint @endpoint end |
Instance Method Details
#healthy? ⇒ Boolean
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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 ⇒ Object
13 14 15 |
# File 'lib/armada/connection/health_check.rb', line 13 def to_s "#{@host}:#{@port}#{@endpoint}" end |