Module: OCI::Retry::Functions::ShouldRetryOnError

Defined in:
lib/oci/retry/functions/should_retry_on_error.rb

Overview

A module containing functions that can be used to determine whether to retry based on the error/exception encountered.

These functions should take a single argument of a Internal::RetryState object

Defined Under Namespace

Classes: ErrorCodeTuple

Constant Summary collapse

DEFAULT_RETRY_MAPPING =
{
  ErrorCodeTuple.new(409, 'IncorrectState') => true,
  ErrorCodeTuple.new(429, 'TooManyRequests') => true,
  ErrorCodeTuple.new(501, 'MethodNotImplemented') => false
}.freeze

Class Method Summary collapse

Class Method Details

.default_retry_strategy_procProc

rubocop:disable Metrics/AbcSize Returns a proc which will retry on Errors::NetworkError and on Errors::ServiceError when the status code is (409, IncorrectState) and (429, TooManyRequests) or an internal server error (any HTTP 5xx except 501 MethodNotImplemented)

Returns:

  • (Proc)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/oci/retry/functions/should_retry_on_error.rb', line 42

def self.default_retry_strategy_proc
  lambda do |retry_state|
    return true if retry_state.last_exception.is_a?(OCI::Errors::NetworkError)
    return false unless retry_state.last_exception.is_a?(OCI::Errors::ServiceError)

    if DEFAULT_RETRY_MAPPING.key?(ErrorCodeTuple.new(retry_state.last_exception.status_code,
                                                     retry_state.last_exception.service_code))
      return DEFAULT_RETRY_MAPPING[ErrorCodeTuple.new(retry_state.last_exception.status_code,
                                                      retry_state.last_exception.service_code)]
    end

    retry_state.last_exception.status_code >= 500
  end
  # rubocop:enable Metrics/AbcSize
end

.retry_on_network_error_throttle_and_internal_server_errorsProc

Returns a proc which will retry on Errors::NetworkError and on Errors::ServiceError when the status code indicates a throttle (HTTP 429) or an internal server error (any HTTP 5xx)

Returns:

  • (Proc)


27
28
29
30
31
32
33
34
# File 'lib/oci/retry/functions/should_retry_on_error.rb', line 27

def self.retry_on_network_error_throttle_and_internal_server_errors
  lambda do |retry_state|
    return true if retry_state.last_exception.is_a?(OCI::Errors::NetworkError)
    return false unless retry_state.last_exception.is_a?(OCI::Errors::ServiceError)

    retry_state.last_exception.status_code == 429 || retry_state.last_exception.status_code >= 500
  end
end