View Source BreakerBox (BreakerBox v0.5.0)
Server for circuit breakers.
Maintains state of registered breakers and their configurations, and allows for querying the status of breakers, as well as enabling and disabling.
Modules can be automatically registered if they implement the
BreakerBox.BreakerConfiguration behaviour and are passed in to start_link/2.
Link to this section Summary
Functions
Retrieve the current status of all registered breakers.
Returns a specification to start this module under a supervisor.
Disable a circuit breaker.
Enable a circuit breaker.
Retrieve the configuration for a breaker.
Increment the error counter for a circuit breaker.
Initializes the breaker box state, attempting to call registration/0 on
every argument passed in, assuming they're a module implementing the
BreakerBox.BreakerConfiguration behaviour. If they are not a module, or don't
implement the behaviour, a warning will be logged indicating how to fix the
issue, and that item will be skipped.
Register a circuit breaker given its name and options.
Retrieve a map with breaker names as keys and
BreakerBox.BreakerConfiguration structs as values.
Remove a circuit breaker.
Reset a breaker that has been tripped. This will only reset breakers that
have been blown via exceeding the error limit in a given time window, and
will not re-enable a breaker that has been disabled via disable/1.
Wrapper around GenServer.start_link/3. Passes the list of modules received
to init/1, which will attempt to register the circuit breakers inside those
modules.
Retrieve the status of a single breaker.
Link to this section Functions
Specs
Retrieve the current status of all registered breakers.
Returns a specification to start this module under a supervisor.
See Supervisor.
Specs
Disable a circuit breaker.
Sets the breaker's status to :breaker_tripped until enable/1 is called for the same
breaker, or the application is restarted.
Will not be reset by calling reset/1.
Specs
Enable a circuit breaker.
Sets the breaker's status to :ok.
Specs
get_config(breaker_name :: term(), process_name :: term()) :: {:ok, BreakerBox.BreakerConfiguration.t()} | {:error, :not_found}
Retrieve the configuration for a breaker.
Specs
Increment the error counter for a circuit breaker.
If this causes the breaker to go over its error limit for its time window,
the breaker will trip, and subsequent calls to status/1 will show it as
{:error, {:breaker_tripped, breaker_name}}.
Specs
init(circuit_breaker_modules :: [module()]) :: {:ok, %{optional(term()) => BreakerBox.BreakerConfiguration.t()}}
Initializes the breaker box state, attempting to call registration/0 on
every argument passed in, assuming they're a module implementing the
BreakerBox.BreakerConfiguration behaviour. If they are not a module, or don't
implement the behaviour, a warning will be logged indicating how to fix the
issue, and that item will be skipped.
register(breaker_name, breaker_options, process_name \\ __MODULE__)
View SourceSpecs
register( breaker_name :: term(), breaker_options :: BreakerBox.BreakerConfiguration.t(), process_name :: term() ) :: :ok | :reset | {:error, reason :: term()}
Register a circuit breaker given its name and options.
_MODULE_ is a good default breaker name, but can be a string, atom, or anything you want. Re-using a breaker name in multiple places will overwrite with the last configuration.
Specs
registered(process_name :: term()) :: %{ optional(term()) => BreakerBox.BreakerConfiguration.t() }
Retrieve a map with breaker names as keys and
BreakerBox.BreakerConfiguration structs as values.
Specs
Remove a circuit breaker.
Specs
Reset a breaker that has been tripped. This will only reset breakers that
have been blown via exceeding the error limit in a given time window, and
will not re-enable a breaker that has been disabled via disable/1.
Specs
start_link(circuit_breaker_modules :: [module()], process_name :: term()) :: {:ok, pid()} | {:error, {:already_started, pid()}} | {:error, reason :: term()} | {:stop, reason :: term()} | :ignore
Wrapper around GenServer.start_link/3. Passes the list of modules received
to init/1, which will attempt to register the circuit breakers inside those
modules.
Modules passed in are expected to implement the BreakerBox.BreakerConfiguration
behaviour via @behaviour BreakerBox.BreakerConfiguration, which will require them to
have a method named registration/0 that returns a 2-tuple containing the
breaker's name and configuration options.
Specs
Retrieve the status of a single breaker.