Class: Rookout::ComWs::Backoff

Inherits:
Object
  • Object
show all
Defined in:
lib/rookout/com_ws/backoff.rb

Instance Method Summary collapse

Constructor Details

#initializeBackoff

Returns a new instance of Backoff.



6
7
8
9
# File 'lib/rookout/com_ws/backoff.rb', line 6

def initialize
  @connect_time = nil
  reset_backoff
end

Instance Method Details

#after_connectObject



19
20
21
# File 'lib/rookout/com_ws/backoff.rb', line 19

def after_connect
  @connect_time = Time.now
end

#after_disconnectObject



11
12
13
14
15
16
17
# File 'lib/rookout/com_ws/backoff.rb', line 11

def after_disconnect
  reset_backoff if @connect_time && Time.new > @connect_time + Config.backoff_reset_time
  @connect_time = nil

  sleep @next_backoff
  @next_backoff = [@next_backoff * 2, Config.backoff_max_time].min
end