Skip to content

Add circuit breaker for external store adapters (v1.6.0)#61

Merged
eclectic-coding merged 2 commits into
mainfrom
feature/v1.6.0
Jun 2, 2026
Merged

Add circuit breaker for external store adapters (v1.6.0)#61
eclectic-coding merged 2 commits into
mainfrom
feature/v1.6.0

Conversation

@eclectic-coding
Copy link
Copy Markdown
Owner

Summary

  • SafeMemoize::Stores::CircuitBreaker — a Stores::Base wrapper that protects any external store adapter with a three-state circuit breaker. When the store raises, reads return MISS (triggering the per-instance fallback cache) and writes are no-ops, so callers never see exceptions.
  • circuit_breaker: option on memoize — auto-wraps the configured store: adapter; accepts true for defaults (error_threshold: 5, probe_interval: 30 s) or a Hash to customise; also accepted by safe_memoize_options as a class-wide default.
  • Does not double-wrap a store already wrapped in CircuitBreaker; raises ArgumentError if no store is configured.

States: :closed (normal, errors counted) → :open (store bypassed until probe interval elapses) → :half_open (probe: success closes circuit, failure re-opens and resets timer). Any success in :closed resets the consecutive error counter so transient blips don't accumulate.

Test plan

  • bundle exec rake — 865 examples, 0 failures, lint clean
  • 32 new examples covering: state transitions (closed→open→half_open→closed), MISS fallback on read, write no-op when open, error counter reset on success, reset!, validation errors, circuit_breaker: memoize option (true / Hash / invalid), no double-wrapping, end-to-end fallback to per-instance cache

🤖 Generated with Claude Code

eclectic-coding and others added 2 commits June 2, 2026 14:41
- `SafeMemoize::Stores::CircuitBreaker` — Stores::Base wrapper with
  three-state circuit breaker (closed/open/half_open); reads return MISS
  and writes are no-ops when open, falling back to the per-instance hash
- `circuit_breaker:` option on `memoize` auto-wraps the configured store;
  accepts `true` (defaults: error_threshold 5, probe_interval 30 s) or a
  Hash with custom values; raises if no store is configured
- Does not double-wrap a store already wrapped in CircuitBreaker
- Successful calls in closed state reset the consecutive error counter
- `circuit_breaker:` accepted by `safe_memoize_options` as a class default
- 32 new tests covering state transitions, fallback behavior, introspection,
  validation, and the memoize option

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Update CHANGELOG, ROADMAP, and README for Stores::CircuitBreaker
and the circuit_breaker: memoize option.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@eclectic-coding eclectic-coding merged commit 0abc386 into main Jun 2, 2026
4 checks passed
@eclectic-coding eclectic-coding deleted the feature/v1.6.0 branch June 2, 2026 18:44
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.

1 participant