A lightweight ETS-backed circuit breaker for Oban workers.
One process owns the ETS table; telemetry handlers write messages to that process, keeping Oban telemetry callbacks fast. Samples are kept only for the configured rolling window.
Summary
Functions
Returns a specification to start this module under a supervisor.
Records a failed job completion asynchronously.
Records a failed job completion and its telemetry duration in native units.
Records a job start, allowing enqueue/start rates to be inspected from ETS.
Records a successful job completion asynchronously.
Records a successful job completion and its telemetry duration in native units.
Checks open circuits and attempts recovery after their cooldown.
Manually closes a worker circuit and optionally resumes its queue.
Returns current rolling counters and duration aggregates for a worker.
Starts a breaker for one named Oban instance.
Returns the current circuit status for a worker.
Lists rolling snapshots for every worker observed by this breaker.
Types
@type action() :: :pause_queue | :emit_only
@type policy() :: %{ optional(:failure_threshold) => float(), optional(:minimum_samples) => pos_integer(), optional(:cooldown_ms) => pos_integer(), optional(:action) => action(), optional(:auto_recover) => boolean() }
@type snapshot() :: %{ worker: worker(), queue: queue() | nil, status: status(), samples: non_neg_integer(), failures: non_neg_integer(), failure_rate: float(), starts: non_neg_integer(), duration: %{ count: non_neg_integer(), average: float(), max: non_neg_integer() } }
@type status() :: :closed | :open
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec record_failure(GenServer.server(), worker(), queue()) :: :ok
Records a failed job completion asynchronously.
@spec record_failure(GenServer.server(), worker(), queue(), integer() | nil) :: :ok
Records a failed job completion and its telemetry duration in native units.
@spec record_start(GenServer.server(), worker(), queue()) :: :ok
Records a job start, allowing enqueue/start rates to be inspected from ETS.
@spec record_success(GenServer.server(), worker(), queue()) :: :ok
Records a successful job completion asynchronously.
@spec record_success(GenServer.server(), worker(), queue(), integer() | nil) :: :ok
Records a successful job completion and its telemetry duration in native units.
@spec recover_due(GenServer.server()) :: :ok
Checks open circuits and attempts recovery after their cooldown.
@spec reset(GenServer.server(), worker(), keyword()) :: :ok | {:error, :not_open}
Manually closes a worker circuit and optionally resumes its queue.
@spec snapshot(GenServer.server(), worker()) :: snapshot()
Returns current rolling counters and duration aggregates for a worker.
@spec start_link(keyword()) :: GenServer.on_start()
Starts a breaker for one named Oban instance.
@spec status(GenServer.server(), worker()) :: status()
Returns the current circuit status for a worker.
@spec workers(GenServer.server()) :: [snapshot()]
Lists rolling snapshots for every worker observed by this breaker.