Class: HatiConfig::Cache::BackoffConfig

Inherits:
Object
  • Object
show all
Includes:
NumericConfigurable
Defined in:
lib/hati_config/cache.rb

Overview

BackoffConfig class handles backoff configuration and behavior.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NumericConfigurable

included

Constructor Details

#initialize ⇒ BackoffConfig

Returns a new instance of BackoffConfig.



183
184
185
186
187
# File 'lib/hati_config/cache.rb', line 183

def initialize
  @initial = 1
  @multiplier = 2
  @max = 300
end

Instance Attribute Details

#initial ⇒ Object (readonly)

Returns the value of attribute initial.



179
180
181
# File 'lib/hati_config/cache.rb', line 179

def initial
  @initial
end

#max ⇒ Object (readonly)

Returns the value of attribute max.



179
180
181
# File 'lib/hati_config/cache.rb', line 179

def max
  @max
end

#multiplier ⇒ Object (readonly)

Returns the value of attribute multiplier.



179
180
181
# File 'lib/hati_config/cache.rb', line 179

def multiplier
  @multiplier
end

Instance Method Details

#backoff_time(attempt) ⇒ Integer

Gets the backoff time for a given attempt.

Parameters:

  • attempt (Integer) —

    The attempt number

Returns:

  • (Integer) —

    The backoff time in seconds



193
194
195
196
# File 'lib/hati_config/cache.rb', line 193

def backoff_time(attempt)
  time = initial * (multiplier**(attempt - 1))
  [time, max].min
end