Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BreakableFunction ¶
type BreakableFunction func() (interface{}, error)
BreakableFunction is a request which will be performed inside the CircuitBreaker
type CircuitBreaker ¶
type CircuitBreaker interface {
Execute(function BreakableFunction) (interface{}, error)
}
CircuitBreaker represents a state machine to prevent sending requests that are likely to fail.
func NewCircuitBreaker ¶
func NewCircuitBreaker(settings Settings, logger flamingo.Logger) CircuitBreaker
NewCircuitBreaker returns a new CircuitBreaker configured with the given Settings.
type Settings ¶
type Settings struct { Name string MaxRequests uint32 Interval time.Duration Timeout time.Duration OnStateChange StateChangeFunction ReadyToTrip func(counts gobreaker.Counts) bool }
Settings is used to pass settings to the CircuitBreaker
Name is the name of the CircuitBreaker.
MaxRequests is the maximum number of requests allowed to pass through when the CircuitBreaker is half-open. If MaxRequests is 0, the CircuitBreaker allows only 1 request.
Interval is the cyclic period of the closed state for the CircuitBreaker to clear the internal Counts. If Interval is 0, the CircuitBreaker doesn't clear internal Counts during the closed state.
Timeout is the period of the open state, after which the state of the CircuitBreaker becomes half-open. If Timeout is 0, the timeout value of the CircuitBreaker is set to 60 seconds.
OnStateChange is called whenever the state of the CircuitBreaker changes.
ReadyToTrip is called with a copy of Counts whenever a request fails in the closed state. If ReadyToTrip returns true, the CircuitBreaker will be placed into the open state. If ReadyToTrip is nil, readyToTrip from this package is used.
type State ¶
type State interface {
String() string
}
State represents the current state of the CircuitBreaker
type StateChangeFunction ¶
type StateChangeFunction func(cb CircuitBreaker, from, to State)
StateChangeFunction is called when the CircuitBreaker changes its state