Class: Opbeat::ClientState

Inherits:
Object
  • Object
show all
Defined in:
lib/opbeat/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ ClientState

Returns a new instance of ClientState.



12
13
14
15
16
# File 'lib/opbeat/client.rb', line 12

def initialize(configuration)
  @configuration = configuration
  @retry_number = 0
  @last_check = Time.now
end

Instance Method Details

#set_failObject



27
28
29
30
31
# File 'lib/opbeat/client.rb', line 27

def set_fail
  @status = :error
  @retry_number += 1
  @last_check = Time.now
end

#set_successObject



33
34
35
36
37
# File 'lib/opbeat/client.rb', line 33

def set_success
  @status = :online
  @retry_number = 0
  @last_check = nil
end

#should_try?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
# File 'lib/opbeat/client.rb', line 18

def should_try?
  return true if @status == :online
    
  interval = ([@retry_number, 6].min() ** 2) * @configuration[:backoff_multiplier]
  return true if Time.now - @last_check > interval

  false
end