Circuit breaker state machine for resilient calls.
Summary
Functions
Check if a request should be allowed.
Execute a function through the circuit breaker.
Create a new circuit breaker.
Record a failed call.
Ignore a call result without changing breaker health.
Record a successful call.
Reset the circuit breaker to a closed state.
Get the current circuit breaker state.
Types
@type state() :: :closed | :open | :half_open
@type t() :: %Foundation.CircuitBreaker{ failure_count: non_neg_integer(), failure_threshold: pos_integer(), half_open_calls: non_neg_integer(), half_open_max_calls: pos_integer(), name: String.t(), opened_at: integer() | nil, reset_timeout_ms: pos_integer(), state: state() }
Functions
Check if a request should be allowed.
@spec call(t(), (-> result), keyword()) :: {result | {:error, :circuit_open}, t()} when result: term()
Execute a function through the circuit breaker.
Create a new circuit breaker.
Record a failed call.
Ignore a call result without changing breaker health.
This is useful for outcomes such as rate-limits where callers want shared coordination, but do not want the circuit breaker to count the result as a success or a failure.
Record a successful call.
Reset the circuit breaker to a closed state.
Get the current circuit breaker state.