View Source TripSwitch.Breaker (TripSwitch v0.1.4)
This is the underlying model which the trip switch uses. A breaker
keeps track of number of currents it received and also the count
of surges it got from the currents it has handled. A breaker
has three states, closed, open and half_open. The
closed state is considered the working state while the
remaining states are broken states.
The only time a breaker enters the half_open state is when it just
got repaired after it got broken from a bad current it handled. The
breaker is then transitioned into the closed state (if the next
current is a good one) or open state (if the next current is bad).
Link to this section Summary
Functions
Check if the breaker is broken.
Handle the given current and transition the breaker state if needed.
Repair the breaker.
Confirm if breaker is repairable.
Reset breaker into its initial working state.
Link to this section Types
@type current() :: {:error | :ok, term()}
@type state() :: :closed | :half_open | :open
@type t() :: %TripSwitch.Breaker{ counter: pos_integer(), repair_time: pos_integer(), state: state(), surges: pos_integer(), threshold: pos_integer() }
Link to this section Functions
Check if the breaker is broken.
Handle the given current and transition the breaker state if needed.
Repair the breaker.
Confirm if breaker is repairable.
A breaker is only repairable if it repair_time is greater than 0.
Reset breaker into its initial working state.