-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Labels
Description
Implement a circuit breaker pattern for the StellarClient to prevent cascading failures when the Stellar Horizon API is unavailable. The circuit breaker should automatically open after repeated failures and recover after a timeout.
Requirements:
- Implement a
CircuitBreakerstruct with states:Closed,Open,HalfOpen - Configuration via
CircuitBreakerConfig:pub struct CircuitBreakerConfig { pub failure_threshold: u32, // failures before opening pub success_threshold: u32, // successes in HalfOpen before closing pub timeout_secs: u64, // seconds before trying HalfOpen }
- Wrap
StellarClientcalls: if the breaker isOpen, return an error immediately without making an HTTP request - After
timeout_secs, transition toHalfOpenand allow one request through - If that request succeeds
success_thresholdtimes, close the circuit; if it fails, reopen it - Expose circuit state in the
GET /healthresponse - Use
std::sync::atomictypes for thread-safe state management
Acceptance Criteria:
- Circuit opens after
failure_thresholdconsecutive failures - While open, requests fail immediately with a specific
CircuitOpenError - Unit tests for all three state transitions
- Health endpoint accurately reflects circuit state
Reactions are currently unavailable