Simple three-state circuit breaker for the Railsr API.
States:
- closed — normal operation; failures are counted
- open — requests are rejected immediately without hitting the network
- half-open — one probe request is allowed through to test recovery
Thresholds
- Failure threshold: 5 consecutive failures → open
- Recovery timeout: 30 seconds → half-open
- Probe success → closed; probe failure → open (reset timer)
Summary
Functions
Check whether a request should be allowed through.
Returns a specification to start this module under a supervisor.
Record a failed request (increments counter, may trip breaker).
Record a successful request (resets failure count, closes if half-open).
Start the circuit breaker process.
Returns the current circuit state.
Functions
@spec check() :: :ok | {:error, :circuit_open}
Check whether a request should be allowed through.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec record_failure() :: :ok
Record a failed request (increments counter, may trip breaker).
@spec record_success() :: :ok
Record a successful request (resets failure count, closes if half-open).
@spec start_link(keyword()) :: GenServer.on_start()
Start the circuit breaker process.
@spec state() :: :closed | :open | :half_open
Returns the current circuit state.