Skip to content

Add override config layer for forced retry behavior#121

Draft
kamui wants to merge 2 commits intomainfrom
feat-override
Draft

Add override config layer for forced retry behavior#121
kamui wants to merge 2 commits intomainfrom
feat-override

Conversation

@kamui
Copy link
Owner

@kamui kamui commented Mar 7, 2026

Summary

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

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). Previously, Retriable.configure could only set defaults that local options would override.

API

  • Retriable.override(opts) — accepts a hash of config keys to force globally. Only the specified keys are overridden; non-specified keys still respect configure defaults and local options.
  • Retriable.reset_override — clears the override.
  • Contexts are supported: Retriable.override(contexts: { api: { tries: 1 } })
  • Invalid 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 using deep_merge. This means:

  • Changes to Retriable.configure after override still take effect for non-overridden keys
  • The override is not a snapshot — it is a transparent layer

Changes

  • lib/retriable.rb — adds override, reset_override, deep_merge, and supporting merge helpers
  • spec/retriable_spec.rb — 12 new tests covering override precedence, contexts, edge cases, and validation
  • 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.

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