Method: VORuby::Misc::ConnectionMonitor#initialize

Defined in:
lib/voruby/misc/connection_monitor.rb

#initialize(url, polling_freq = 600, timeout = 5) ⇒ ConnectionMonitor

Place a monitor on the specified URL. By default the URL will be “pinged” every 600 seconds and will timeout if it doesn’t receive a response within 5 seconds.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/voruby/misc/connection_monitor.rb', line 41

def initialize(url, polling_freq=600, timeout=5)
  @pinger = Net::Ping::HTTP.new(url)
    
  self.polling_freq = polling_freq
  self.url = url
  self.timeout = timeout
    
  @interrupted = false
    
  self.on_failure = Proc.new{ |pinger, monitor|
    puts "Connection to #{monitor.url} failed: #{pinger.exception}."
  }
  self.on_success = Proc.new{ |pinger, monitor| }
  self.on_interrupt = Proc.new{ @interrupted = true }
    
  trap("INT"){ self.on_interrupt.call }
end