Module: RSMP::Proxy::Modules::Watchdogs
- Included in:
- RSMP::Proxy
- Defined in:
- lib/rsmp/proxy/modules/watchdogs.rb
Overview
Watchdog functionality for monitoring connection health Handles sending and receiving watchdog messages
Instance Method Summary collapse
- #check_watchdog_timeout(now) ⇒ Object
- #process_watchdog(message) ⇒ Object
- #send_watchdog(now = Clock.now) ⇒ Object
- #start_watchdog ⇒ Object
- #stop_watchdog ⇒ Object
- #watchdog_send_timer(now) ⇒ Object
- #with_watchdog_disabled ⇒ Object
Instance Method Details
#check_watchdog_timeout(now) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rsmp/proxy/modules/watchdogs.rb', line 47 def check_watchdog_timeout(now) timeout = @site_settings['timeouts']['watchdog'] latest = @latest_watchdog_received + timeout left = latest - now return unless left.negative? str = "No Watchdog received within #{timeout} seconds" log str, level: :warning distribute MissingWatchdog.new(str) end |
#process_watchdog(message) ⇒ Object
58 59 60 61 62 |
# File 'lib/rsmp/proxy/modules/watchdogs.rb', line 58 def process_watchdog() log "Received #{message.type}", message: , level: :log @latest_watchdog_received = Clock.now acknowledge end |
#send_watchdog(now = Clock.now) ⇒ Object
41 42 43 44 45 |
# File 'lib/rsmp/proxy/modules/watchdogs.rb', line 41 def send_watchdog(now = Clock.now) = RSMP::Watchdog.new({ 'wTs' => clock.to_s }) @latest_watchdog_send_at = now end |
#start_watchdog ⇒ Object
7 8 9 10 |
# File 'lib/rsmp/proxy/modules/watchdogs.rb', line 7 def start_watchdog log "Starting watchdog with interval #{@site_settings['intervals']['watchdog']} seconds", level: :debug @watchdog_started = true end |
#stop_watchdog ⇒ Object
12 13 14 15 |
# File 'lib/rsmp/proxy/modules/watchdogs.rb', line 12 def stop_watchdog log 'Stopping watchdog', level: :debug @watchdog_started = false end |
#watchdog_send_timer(now) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rsmp/proxy/modules/watchdogs.rb', line 25 def watchdog_send_timer(now) return unless @watchdog_started return if @site_settings['intervals']['watchdog'] == :never if @latest_watchdog_send_at.nil? send_watchdog now else # we add half the timer interval to pick the timer # event closes to the wanted wathcdog interval diff = now - @latest_watchdog_send_at if (diff + (0.5 * @site_settings['intervals']['timer'])) >= @site_settings['intervals']['watchdog'] send_watchdog now end end end |
#with_watchdog_disabled ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/rsmp/proxy/modules/watchdogs.rb', line 17 def with_watchdog_disabled was = @watchdog_started stop_watchdog if was yield ensure start_watchdog if was end |