Class: Sensu::Extension::ExponentialDecayTimer

Inherits:
Object
  • Object
show all
Defined in:
lib/sensu/extensions/graphite.rb

Overview

ExponentialDecayTimer

Implement an exponential backoff timer for reconnecting to metrics backends.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExponentialDecayTimer

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_timeObject

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