Class: Factorix::HTTP::RetryStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/factorix/http/retry_strategy.rb,
sig/factorix/http/retry_strategy.rbs

Overview

Class that manages retry strategy with exponential backoff and randomization

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil, **options) ⇒ RetryStrategy

Initialize a new retry strategy with customizable options

Parameters:

Options Hash (**options):

  • :tries (Integer) —

    Number of attempts (including the initial try)

  • :base_interval (Float) —

    Initial interval between retries (seconds)

  • :multiplier (Float) —

    Exponential backoff multiplier

  • :rand_factor (Float) —

    Randomization factor

  • :on (Array<Class>) —

    Exception classes to retry on

  • :on_retry (Proc) —

    Callback called on each retry



43
44
45
46
# File 'lib/factorix/http/retry_strategy.rb', line 43

def initialize(logger: nil, **options)
  super(logger:)
  @options = configure_options(options)
end

Instance Attribute Details

#logger ⇒ Dry::Logger::Dispatcher (readonly)

Returns the value of attribute logger.



9
10
11
# File 'sig/factorix/http/retry_strategy.rbs', line 9

def logger
  @logger
end

Instance Method Details

#with_retry { ... } ⇒ Object

Execute the block with automatic retry on specified exceptions. Uses exponential backoff with randomization for retry intervals

Yields:

  • Block to execute

Returns:

  • (Object) —

    Return value of the block

Raises:

  • (StandardError) —

    If the block fails after all retries



54
# File 'lib/factorix/http/retry_strategy.rb', line 54

def with_retry(&) = Retriable.retriable(**@options, &)