Class: EventedBluepill::ProcessConditions::Http
- Inherits:
-
ProcessCondition
- Object
- Coolio::TimerWatcher
- ProcessCondition
- EventedBluepill::ProcessConditions::Http
- Defined in:
- lib/evented_bluepill/process_conditions/http.rb
Instance Attribute Summary
Attributes inherited from ProcessCondition
#every, #fires, #logger, #name, #process, #process_condition
Instance Method Summary collapse
- #check(value) ⇒ Object
-
#initialize(name, process, options = {}) ⇒ Http
constructor
A new instance of Http.
- #run ⇒ Object
Methods inherited from ProcessCondition
#clear_history!, #format_value, #to_s
Constructor Details
#initialize(name, process, options = {}) ⇒ Http
Returns a new instance of Http.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/evented_bluepill/process_conditions/http.rb', line 12 def initialize(name, process, = {}) @uri = URI.parse([:url]) @kind = case [:kind] when Fixnum then Net::HTTPResponse::CODE_TO_OBJ[[:kind].to_s] when String, Symbol then Net.const_get("HTTP#{[:kind].to_s.camelize}") else Net::HTTPSuccess end @pattern = [:pattern] || nil @open_timeout = ([:open_timeout] || [:timeout] || 5).to_i @read_timeout = ([:read_timeout] || [:timeout] || 5).to_i super end |
Instance Method Details
#check(value) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/evented_bluepill/process_conditions/http.rb', line 40 def check(value) return false unless value.kind_of?(@kind) return true unless @pattern return false unless value.class.body_permitted? @pattern === value.body end |
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/evented_bluepill/process_conditions/http.rb', line 27 def run session = Net::HTTP.new(@uri.host, @uri.port) session.open_timeout = @open_timeout session.read_timeout = @read_timeout hide_net_http_bug do session.start do |http| http.get(@uri.path) end end rescue $! end |