class OpenApiSDK::Utils::RetryConfig
def initialize(backoff: nil, retry_connection_errors: nil, strategy: nil)
def initialize(backoff: nil, retry_connection_errors: nil, strategy: nil) @backoff = T.let(backoff, T.nilable(BackoffStrategy)) @retry_connection_errors = T.let(retry_connection_errors, T.nilable(T::Boolean)) @strategy = T.let(strategy, T.nilable(::String)) end
def to_faraday_retry_options(initial_time:)
def to_faraday_retry_options(initial_time:) retry_options = { # must overwrite default max of 2 retries and it must be positive max: 1_000_000_000, # ensure all HTTP methods are retried, especially via retry_if methods: [], } if @retry_connection_errors retry_options[:exceptions] = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed] end if @strategy == 'backoff' && @backoff retry_options[:backoff_factor] = @backoff.exponent unless @backoff.exponent.nil? retry_options[:interval] = (@backoff.initial_interval.to_f / 1000) unless @backoff.initial_interval.nil? retry_options[:max_interval] = @backoff.max_interval unless @backoff.max_interval.nil? unless @backoff.max_elapsed_time.nil? stop_time = initial_time + (@backoff.max_elapsed_time.to_f / 1000) retry_options[:retry_if] = ->(_env, _exc) { Time.now < stop_time } end end retry_options end