Class: Etcd::Heartbeat
- Inherits:
-
Object
- Object
- Etcd::Heartbeat
- Includes:
- Loggable
- Defined in:
- lib/etcd/heartbeat.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#freq ⇒ Object
Returns the value of attribute freq.
Instance Method Summary collapse
-
#heartbeat_command ⇒ Object
The command to check leader online status, runs in background and is resilient to failures.
-
#initialize(client, freq) ⇒ Heartbeat
constructor
A new instance of Heartbeat.
-
#start_heartbeat_if_needed ⇒ Object
Initiates heartbeating the leader node in a background thread ensures, that observers are refreshed after leader re-election.
Methods included from Loggable
Constructor Details
#initialize(client, freq) ⇒ Heartbeat
Returns a new instance of Heartbeat.
7 8 9 10 |
# File 'lib/etcd/heartbeat.rb', line 7 def initialize(client, freq) @client = client @freq = freq end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
5 6 7 |
# File 'lib/etcd/heartbeat.rb', line 5 def client @client end |
#freq ⇒ Object
Returns the value of attribute freq.
6 7 8 |
# File 'lib/etcd/heartbeat.rb', line 6 def freq @freq end |
Instance Method Details
#heartbeat_command ⇒ Object
The command to check leader online status, runs in background and is resilient to failures
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/etcd/heartbeat.rb', line 29 def heartbeat_command logger.debug("heartbeat_command: enter ") logger.debug(client.observers_overview.join(", ")) begin client.refresh_observers_if_needed client.update_cluster if client.status == :down client.get("foo") rescue Exception => e client.status = :down logger.debug "heartbeat - #{e.message} #{e.backtrace}" end sleep freq end |
#start_heartbeat_if_needed ⇒ Object
Initiates heartbeating the leader node in a background thread ensures, that observers are refreshed after leader re-election
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/etcd/heartbeat.rb', line 15 def start_heartbeat_if_needed logger.debug("start_heartbeat_if_needed - enter") return if freq == 0 return if @heartbeat_thread @heartbeat_thread = Thread.new do while true do heartbeat_command end end end |