Class: Abalone::Watchdog
- Inherits:
-
Object
- Object
- Abalone::Watchdog
- Defined in:
- lib/abalone/watchdog.rb
Instance Method Summary collapse
-
#initialize(period, options) ⇒ Watchdog
constructor
A new instance of Watchdog.
Constructor Details
#initialize(period, options) ⇒ Watchdog
Returns a new instance of Watchdog.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/abalone/watchdog.rb', line 2 def initialize(period, ) raise 'Watchdog needs a port to be set' unless .include? :port raise 'Watchdog needs a logger to be set' unless .include? :logger logger = [:logger] Thread.new do require 'net/http' sleep 5 # give the service time to wake up logger.warn "Starting watchdog with period #{period}" loop do http = Net::HTTP.new('localhost', [:port]) http.open_timeout = 1 http.read_timeout = 1 begin http.start http.request_get('/heartbeat/ping') do |res| logger.debug "Heartbeat response: #{res.read_body}" system('systemd-notify WATCHDOG=1') end rescue => e logger.warn 'Abalone service failed heartbeat check!' logger.debug e. end sleep period end end end |