Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrCircuitOpen is returned when the state of Circuit Breaker is open. ErrCircuitOpen = errors.New("circuit breaker is open") )
Functions ¶
This section is empty.
Types ¶
type CircuitBreaker ¶
type CircuitBreaker struct { OnSuccess func() // OnSuccess will be called when Action can be processed, when state is StateClosed or StateHalfOpen OnFailure func() // OnFailure will be triggered when CircuitBreaker moved to StateOpen and Action failed to execute and will return error. // contains filtered or unexported fields }
CircuitBreaker component that is designed to prevent sending execution that are likely to fail.
func NewCircuitBreaker ¶
func NewCircuitBreaker(cfg Configuration) (*CircuitBreaker, error)
NewCircuitBreaker creates a new CircuitBreaker instance with the specified configuration.
func (*CircuitBreaker) GetState ¶
func (cb *CircuitBreaker) GetState() State
GetState returns current state of the Circuit Breaker.
type Configuration ¶
type Configuration struct { MaxFailuresThreshold string `json:"cb_max_failures_threshold,omitempty"` ResetTimeout string `json:"cb_reset_timeout,omitempty"` }
Configuration for CircuitBreaker:
MaxFailuresThreshold Maximum number of failures allowed.
ResetTimeout in seconds, is the period of the open state. After which the state of the CircuitBreaker becomes half-open. fields can be used for example as ENV variables in your project like MY_APP_CB_MAX_FAILURES_THRESHOLD:"3"
Click to show internal directories.
Click to hide internal directories.