Class: WebMonitor::Requester
- Inherits:
-
Object
- Object
- WebMonitor::Requester
- Defined in:
- lib/web-monitor/requester.rb
Overview
Request URL and return time and status
Instance Attribute Summary collapse
-
#benchmark ⇒ Object
writeonly
Sets the attribute benchmark.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #check(url) ⇒ Object
-
#initialize(config) ⇒ Requester
constructor
A new instance of Requester.
Constructor Details
#initialize(config) ⇒ Requester
Returns a new instance of Requester.
11 12 13 14 15 |
# File 'lib/web-monitor/requester.rb', line 11 def initialize(config) @limit = config.response_time_limit @timeout = @limit + 1.0 @benchmark = Benchmark end |
Instance Attribute Details
#benchmark=(value) ⇒ Object (writeonly)
Sets the attribute benchmark
9 10 11 |
# File 'lib/web-monitor/requester.rb', line 9 def benchmark=(value) @benchmark = value end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/web-monitor/requester.rb', line 8 def status @status end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
8 9 10 |
# File 'lib/web-monitor/requester.rb', line 8 def time @time end |
Instance Method Details
#check(url) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/web-monitor/requester.rb', line 17 def check(url) Timeout::timeout(@timeout) do time = @benchmark.measure { get(url.strip) } @time = time.real.to_f end rescue Timeout::Error @time = @timeout @status = 0 end |