Documentation
¶
Index ¶
Constants ¶
const ( // DefaultNumBuckets is the default number of buckets of a circuit breaker. Value = 10. DefaultNumBuckets = 10 // DefaultBucketDuration is the default duration of a bucket. Value = 1s. DefaultBucketDuration = 1 * time.Second // DefaultDurationOfBreak is the default duration of a circuit breaker break. Value = 5s DefaultDurationOfBreak = 5 * time.Second )
Variables ¶
var ErrCircuitOpen = errors.New("circuit breaker is open")
ErrCircuitOpen is the error returned by FastCircuitBreaker.Allow() when the circuit is open.
var ErrCircuitStopped = errors.New("circuit breaker is stopped")
ErrCircuitStopped is the error returned by FastCircuitBreaker.Allow() when the circuit is stopped.
Functions ¶
func DefaultShouldTrip ¶
DefaultShouldTrip is the default implementation of the ShouldTrip function. If will trip the circuit when there has been at least 20 executions and at least 50% of the executions failed.
Types ¶
type Configuration ¶
type Configuration struct { NumBuckets int BucketDuration time.Duration DurationOfBreak time.Duration ShouldTrip ShouldTripFunc }
Configuration is a struct used to configure a circuit breaker.
type FastBreaker ¶
type FastBreaker interface { // Configuration returns the actual configuration used to create the circuit breaker. Configuration() Configuration // Stop releases the circuit breaker resources. Stop() // Allow checks if the circuit breaker should allow the execution to proceed. // Returns a function to report if the execution was successful when the execution is allowed or an // error when it is not. Allow() (func(bool), error) // State returns the current State of the circuit breaker. State() State // Executions returns the number of executions the circuit breaker has allowed. Executions() uint64 // Failures returns the number of executions reported as failed. Failures() uint64 // Rejected returns the number of executions the circuit breaker has rejected. Rejected() uint64 // RollingCounters returns the rolling executions and failures. RollingCounters() (uint64, uint64) }
FastBreaker is the interface implemented by the circuit breakers.
func New ¶
func New(configuration Configuration) FastBreaker
New creates a new CircuitBreaker with the passed Configuration.
type ShouldTripFunc ¶
A ShouldTripFunc tells the circuit breaker to trip when it returns true. If it returns false, the circuit breaker will remain closed.
type State ¶
type State uint32
State represents the state of a circuit breaker.
const ( // StateStopped is the circuit breaker state when it is stopped. StateStopped State = iota // StateClosed is the circuit breaker state when it is allowing executions. StateClosed // StateHalfOpen is the circuit breaker state when it tests if it should remain open // or reset to the closed state. StateHalfOpen // StateOpen is the circuit breaker state when it is rejecting executions. StateOpen )