Class: Watchdog

Inherits:
Object
  • Object
show all
Defined in:
lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/watchdog.rb

Overview

Copyright 2026 IBM Corp. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Constant Summary collapse

WATCHDOG_CONFIG =
{
  check_interval: 60,
  heartbeat_timeout: 120
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Watchdog

Returns a new instance of Watchdog.



23
24
25
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/watchdog.rb', line 23

def initialize(client)
  @client = client
end

Instance Method Details

#startObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/watchdog.rb', line 27

def start
  Thread.new do
    loop do
      sleep WATCHDOG_CONFIG[:check_interval]

      break unless @client.connected?

      heartbeat_age =
        Time.now - @client.last_heartbeat_at

      next unless heartbeat_age >
                  WATCHDOG_CONFIG[:heartbeat_timeout]

      puts "Heartbeat timeout detected"

      @client.handle_disconnect(
        "Heartbeat timeout"
      )

      break
    end
  end
end