Class: Sensu::Extension::ExponentialDecayTimer
- Inherits:
-
Object
- Object
- Sensu::Extension::ExponentialDecayTimer
- Defined in:
- lib/sensu/extensions/graphite.rb
Overview
ExponentialDecayTimer
Implement an exponential backoff timer for reconnecting to metrics backends.
Instance Attribute Summary collapse
-
#reconnect_time ⇒ Object
Returns the value of attribute reconnect_time.
Instance Method Summary collapse
- #get_reconnect_time(max_reconnect_time, connection_attempt_count) ⇒ Object
-
#initialize ⇒ ExponentialDecayTimer
constructor
A new instance of ExponentialDecayTimer.
Constructor Details
#initialize ⇒ ExponentialDecayTimer
Returns a new instance of ExponentialDecayTimer.
15 16 17 |
# File 'lib/sensu/extensions/graphite.rb', line 15 def initialize @reconnect_time = 0 end |
Instance Attribute Details
#reconnect_time ⇒ Object
Returns the value of attribute reconnect_time.
13 14 15 |
# File 'lib/sensu/extensions/graphite.rb', line 13 def reconnect_time @reconnect_time end |
Instance Method Details
#get_reconnect_time(max_reconnect_time, connection_attempt_count) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sensu/extensions/graphite.rb', line 19 def get_reconnect_time(max_reconnect_time, connection_attempt_count) if @reconnect_time < max_reconnect_time seconds = @reconnect_time + (2**(connection_attempt_count - 1)) seconds = seconds * (0.5 * (1.0 + rand)) @reconnect_time = if seconds <= max_reconnect_time seconds else max_reconnect_time end end @reconnect_time end |