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— smallmax_attempts, short delays, full jitter, exponential backoff. For low-latency calls where giving up fast is preferable to waiting. -
:conservative— largermax_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. -
:database— short to medium delays with equal jitter for transient database errors (deadlocks, serialization failures, connection drops); these typically self-heal quickly or escalate fast.
-
{ 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, database: { max_attempts: 4, backoff: :exponential, base_delay: 0.05, max_delay: 2.0, jitter: :equal }.freeze }.freeze
- VERSION =
'0.6.0'
Class Method Summary collapse
-
.preset_names ⇒ Array<Symbol>
Names of all registered presets.
-
.run(**options) { ... } ⇒ Object
Execute a block with retry logic.
-
.with_preset(name, **overrides) { ... } ⇒ Object
Execute a block with retry logic using a named preset from PRESETS.
Class Method Details
.preset_names ⇒ Array<Symbol>
Names of all registered presets.
Useful for surfacing the preset list in CLI tooling, dashboards, or validating user-supplied preset names without reaching into PRESETS.
80 81 82 |
# File 'lib/philiprehberger/retry_kit.rb', line 80 def self.preset_names PRESETS.keys end |
.run(**options) { ... } ⇒ Object
Execute a block with retry logic.
22 23 24 |
# File 'lib/philiprehberger/retry_kit.rb', line 22 def self.run(**, &) Executor.new(**).call(&) end |
.with_preset(name, **overrides) { ... } ⇒ Object
96 97 98 99 100 101 |
# File 'lib/philiprehberger/retry_kit.rb', line 96 def self.with_preset(name, **overrides, &) preset = PRESETS[name] raise ArgumentError, "Unknown preset: #{name}" unless preset run(**preset, **overrides, &) end |