Class: WebMonitor::Requester

Inherits:
Object
  • Object
show all
Defined in:
lib/web-monitor/requester.rb

Overview

Request URL and return time and status

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute benchmark to.



9
10
11
# File 'lib/web-monitor/requester.rb', line 9

def benchmark=(value)
  @benchmark = value
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/web-monitor/requester.rb', line 8

def status
  @status
end

#timeObject (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