Method: Auth0::Mixins::HTTPProxy#retry_options

Defined in:
lib/auth0/mixins/httpproxy.rb

#retry_optionsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/auth0/mixins/httpproxy.rb', line 28

def retry_options
  sleep_timer = lambda do |attempt|
    wait = BASE_DELAY * (2**attempt-1) # Exponential delay with each subsequent request attempt.
    wait += rand(wait+1..wait+MAX_REQUEST_RETRY_JITTER) # Add jitter to the delay window.
    wait = [MAX_REQUEST_RETRY_DELAY, wait].min # Cap delay at MAX_REQUEST_RETRY_DELAY.
    wait = [MIN_REQUEST_RETRY_DELAY, wait].max # Ensure delay is no less than MIN_REQUEST_RETRY_DELAY.
    wait / 1000.to_f.round(2) # convert ms to seconds
  end

  tries = 1 + [Integer(retry_count || DEFAULT_RETRIES), MAX_ALLOWED_RETRIES].min # Cap retries at MAX_ALLOWED_RETRIES

  {
    tries: tries,
    sleep: sleep_timer,
    on: Auth0::RateLimitEncountered
  }
end