Class: PostHog::BackoffPolicy Private

Inherits:
Object
  • Object
show all
Includes:
Defaults::BackoffPolicy
Defined in:
lib/posthog/backoff_policy.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Retry backoff policy used by the SDK transport.

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

Constructor Details

#initialize(opts = {}) ⇒ BackoffPolicy

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of BackoffPolicy.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :min_timeout_ms (Numeric)

    The minimum backoff timeout

  • :max_timeout_ms (Numeric)

    The maximum backoff timeout

  • :multiplier (Numeric)

    The value to multiply the current interval with for each retry attempt

  • :randomization_factor (Numeric)

    The randomization factor to use to create a range around the retry interval



19
20
21
22
23
24
25
26
27
# File 'lib/posthog/backoff_policy.rb', line 19

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_intervalNumeric

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the next backoff interval, in milliseconds.

Returns:

  • (Numeric)

    the next backoff interval, in milliseconds.



30
31
32
33
34
35
36
37
# File 'lib/posthog/backoff_policy.rb', line 30

def next_interval
  interval = @min_timeout_ms * (@multiplier**@attempts)
  interval = add_jitter(interval, @randomization_factor)

  @attempts += 1

  [interval, @max_timeout_ms].min
end