Class: Healthaid::Plugin::Http
- Inherits:
-
Object
- Object
- Healthaid::Plugin::Http
- Defined in:
- lib/healthaid/plugin/http.rb
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(status, config, logger) ⇒ Http
constructor
A new instance of Http.
Constructor Details
#initialize(status, config, logger) ⇒ Http
Returns a new instance of Http.
7 8 9 10 11 |
# File 'lib/healthaid/plugin/http.rb', line 7 def initialize(status, config, logger) @status = status @config = config @logger = logger end |
Instance Method Details
#check ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/healthaid/plugin/http.rb', line 13 def check uri = @config.fetch(:uri, 'http://127.0.0.1/') ok = @config[:ok] || [200] case ok when String ok = ok.strip.split(/\s*,\s*/).map {|i| i.to_i } ok = [200] if ok.empty? when Array ok = ok.map {|i| i.to_i } else ok = [ok.to_i] end timeout = @config.fetch(:timeout, 1).to_i @config[:connect_timeout] ||= timeout @config[:inactivity_timeout] ||= timeout http = EM::HttpRequest.new(uri, @config).get http.timeout(timeout) http.callback do if ok.include?(http.response_header.status) @status.add_healthy else @status.add_unhealthy end end http.errback do @status.add_unhealthy end end |