Class: Segment::Analytics::BackoffPolicy
- Inherits:
-
Object
- Object
- Segment::Analytics::BackoffPolicy
- Includes:
- Defaults::BackoffPolicy
- Defined in:
- lib/segment/analytics/backoff_policy.rb
Constant Summary
Constants included from Defaults::BackoffPolicy
Defaults::BackoffPolicy::MAX_TIMEOUT_MS, Defaults::BackoffPolicy::MIN_TIMEOUT_MS, Defaults::BackoffPolicy::MULTIPLIER, Defaults::BackoffPolicy::RANDOMIZATION_FACTOR
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ BackoffPolicy
constructor
A new instance of BackoffPolicy.
-
#next_interval ⇒ Numeric
The next backoff interval, in milliseconds.
Constructor Details
#initialize(opts = {}) ⇒ BackoffPolicy
Returns a new instance of BackoffPolicy.
17 18 19 20 21 22 23 24 |
# File 'lib/segment/analytics/backoff_policy.rb', line 17 def initialize(opts = {}) @min_timeout_ms = opts[:min_timeout_ms] || MIN_TIMEOUT_MS @max_timeout_ms = opts[:max_timeout_ms] || MAX_TIMEOUT_MS @multiplier = opts[:multiplier] || MULTIPLIER @randomization_factor = opts[:randomization_factor] || RANDOMIZATION_FACTOR @attempts = 0 end |
Instance Method Details
#next_interval ⇒ Numeric
Returns the next backoff interval, in milliseconds.
27 28 29 30 31 32 33 34 |
# File 'lib/segment/analytics/backoff_policy.rb', line 27 def next_interval interval = @min_timeout_ms * (@multiplier**@attempts) interval = add_jitter(interval, @randomization_factor) @attempts += 1 [interval, @max_timeout_ms].min end |