Skip to content

Add override config layer for forced retry behavior#121

Merged
kamui merged 5 commits into
mainfrom
feat-override
May 23, 2026
Merged

Add override config layer for forced retry behavior#121
kamui merged 5 commits into
mainfrom
feat-override

Conversation

@kamui
Copy link
Copy Markdown
Owner

@kamui kamui commented Mar 7, 2026

Summary

Adds Retriable.override and Retriable.reset_override APIs that force retry settings over local call options.

Retriable.override(tries: 1, base_interval: 0)

Precedence

override > local options > configure defaults

Use case

Test short-circuiting: in test environments, tries: 1 must win even when production code passes explicit local options like Retriable.retriable(tries: 5). Overrides also force retry behavior over inherited custom intervals unless intervals is explicitly overridden.

API

  • Retriable.override(opts) accepts a non-empty hash of config keys to force globally.
  • Retriable.reset_override clears the override.
  • Contexts are supported: Retriable.override(contexts: { api: { tries: 1 } }).
  • Invalid top-level keys and invalid context override keys raise ArgumentError, consistent with Retriable.retriable.

Example: Rails test setup

# config/initializers/retriable.rb
Retriable.configure do |c|
  c.tries = 3
  c.base_interval = 0.5
end

if Rails.env.test?
  Retriable.override(tries: 1, base_interval: 0, rand_factor: 0)
end

Implementation

The override is stored as a sparse hash delta and merged lazily at each retriable/with_context call. Hash-valued options replace lower-precedence values rather than deep-merging, so forced options remain authoritative.

Changes

  • lib/retriable.rb — adds override, reset_override, validation, and supporting merge helpers
  • spec/retriable_spec.rb — tests override precedence, contexts, edge cases, validation, and order isolation
  • README.md — new Override section, updated Testing section with override examples
  • CHANGELOG.md / lib/retriable/version.rb — version and changelog entries

Closes #108.

Copilot AI review requested due to automatic review settings March 7, 2026 02:22
@kamui kamui marked this pull request as draft March 7, 2026 02:22

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as outdated.

This comment was marked as resolved.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as resolved.

Adds Retriable.override and Retriable.reset_override APIs that force
retry settings over local call options. Uses a simple hash-based API:

  Retriable.override(tries: 1, base_interval: 0)

Override precedence: override > local options > configure defaults

Primary use case is test short-circuiting where tries: 1 must win even
when production code passes explicit local options.
…ix version/changelog

- Deep-dup and freeze override opts to prevent external mutation
- Validate context values are Hash before merging in merged_context_options
- Bump VERSION to 3.4.2 and add 3.4.1 section to CHANGELOG
- Clarify README per-context override wording (top-level overrides already win)
- Add spec coverage for mutation protection and nil context values

This comment was marked as resolved.

@kamui kamui marked this pull request as ready for review May 23, 2026 02:58
@kamui kamui merged commit a9cb252 into main May 23, 2026
13 checks passed
@kamui kamui deleted the feat-override branch May 23, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Question: Short Circuiting Retriable While Testing Your App

2 participants