Module: Philiprehberger::RetryKit

Defined in:
lib/philiprehberger/retry_kit.rb,
lib/philiprehberger/retry_kit/budget.rb,
lib/philiprehberger/retry_kit/backoff.rb,
lib/philiprehberger/retry_kit/version.rb,
lib/philiprehberger/retry_kit/executor.rb,
lib/philiprehberger/retry_kit/circuit_breaker.rb

Defined Under Namespace

Modules: Backoff Classes: Budget, CircuitBreaker, DeadlineExceededError, Error, Executor, TotalTimeoutError

Constant Summary collapse

PRESETS =

Named retry presets — each value is a Hash of keyword arguments accepted by run. Use with_preset to apply one with optional per-call overrides.

Available presets:

  • :aggressive — small max_attempts, short delays, full jitter, exponential backoff. For low-latency calls where giving up fast is preferable to waiting.

  • :conservative — larger max_attempts, longer delays, full jitter, exponential backoff. For background work where success matters more than speed.

  • :network — middle ground tuned for transient HTTP errors; exponential backoff with full jitter.

{
  aggressive: {
    max_attempts: 3,
    backoff: :exponential,
    base_delay: 0.1,
    max_delay: 1.0,
    jitter: :full
  }.freeze,
  conservative: {
    max_attempts: 6,
    backoff: :exponential,
    base_delay: 1.0,
    max_delay: 60.0,
    jitter: :full
  }.freeze,
  network: {
    max_attempts: 4,
    backoff: :exponential,
    base_delay: 0.5,
    max_delay: 30.0,
    jitter: :full
  }.freeze
}.freeze
VERSION =
'0.5.0'

Class Method Summary collapse

Class Method Details

.run(**options) { ... } ⇒ Object

Execute a block with retry logic.

Parameters:

  • options (Hash)

    options passed to Executor.new

Yields:

  • the block to execute

Returns:

  • the block’s return value

See Also:



22
23
24
# File 'lib/philiprehberger/retry_kit.rb', line 22

def self.run(**options, &)
  Executor.new(**options).call(&)
end

.with_preset(name, **overrides) { ... } ⇒ Object

Execute a block with retry logic using a named preset from PRESETS.

The preset’s keyword arguments are merged with overrides (overrides win on conflict) and forwarded to run.

Parameters:

  • name (Symbol)

    the preset name (must be a key of PRESETS)

  • overrides (Hash)

    keyword arguments that override preset values

Yields:

  • the block to execute

Returns:

  • the block’s return value

Raises:

  • (ArgumentError)

    if name is not a known preset

See Also:



75
76
77
78
79
80
# File 'lib/philiprehberger/retry_kit.rb', line 75

def self.with_preset(name, **overrides, &)
  preset = PRESETS[name]
  raise ArgumentError, "Unknown preset: #{name}" unless preset

  run(**preset, **overrides, &)
end