Cyclium. CircuitBreaker
(Cyclium v0.1.5)
Copy Markdown
ETS-backed per-expectation circuit breaker.
States: :closed → :open → :half_open → :closed.
When consecutive failures exceed the threshold, the circuit opens and
rejects new episodes. After half_open_after_ms, the circuit enters
:half_open — allowing one probe episode. If it succeeds, the circuit
closes; if it fails, the circuit reopens.
Configuration
Set circuit_breaker on an expectation:
expect :check_health,
circuit_breaker: %{threshold: 5, half_open_after_ms: 60_000}ETS layout
Key: {actor_id, expectation_id}
Value: %{state: atom, consecutive_failures: int, opened_at: DateTime | nil}
Summary
Functions
Check if an episode is allowed to fire.
Idempotent ETS table creation.
Get the current circuit state for an expectation.
Record a failed episode. Increments failure count and may trip the circuit.
Record a successful episode. Resets the circuit to :closed.
Functions
Check if an episode is allowed to fire.
Returns :ok or {:error, :circuit_open}.
Idempotent ETS table creation.
Get the current circuit state for an expectation.
Record a failed episode. Increments failure count and may trip the circuit.
When the circuit trips and cancel_in_flight: true is set in config,
running/blocked episodes for this actor+expectation are automatically canceled.
Record a successful episode. Resets the circuit to :closed.