Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrCircuitOpen = NewBreakerError("circuit open") ErrTooManyRequests = NewBreakerError("number of requests exceeded the circuit limit") )
View Source
var ( ReasonStateChange = NewResetReason("state changes") ReasonClosedReset = NewResetReason("reset counter in Closed state") )
Functions ¶
This section is empty.
Types ¶
type Breaker ¶
type Breaker func(stats Statistics) bool
type BreakerError ¶
type BreakerError struct {
// contains filtered or unexported fields
}
Implements the error interface
func NewBreakerError ¶
func NewBreakerError(m string) *BreakerError
func (BreakerError) Error ¶
func (e BreakerError) Error() string
type CircuitBreaker ¶
A state machine to prevent sending requests that are likely to fails
func New ¶
func New(opts Options) *CircuitBreaker
Provided an Options, it returns the new Circuit Breaker
func (*CircuitBreaker) Do ¶
func (c *CircuitBreaker) Do(what func() (interface{}, error)) (interface{}, error)
Perform the action if the Circuit Breaker allows it, either in Closed state of in Half-open if the number requests does not exceed the limit. It returns an error of type BreakerError if the Circuit Breaker rejects the task. It treats any panic as regular error and forwards it back to the consumer.
type IsSuccessCallback ¶
type Options ¶
type Options struct { // The name of this Circuit Breaker Name string `json:"name"` // The maximum number of task allowed to be performed during Half-open state MaxDiscoveryRequests uint32 // The timeout of the Open state. // After which, the state transitions to Half-open OpenTimeout time.Duration // The interval for resetting count during Closed state. // For example, the transition to Open should only occur after failed attempts reaches 5, in a 10 seconds window. // To achieve that, you can set this to 10 seconds and set ShouldBreakCircuit to returns a breaker that breaks the circuit after 5 failures. // // By default, the interval is 0, meaning that it doesn't reset the count ResetCountInterval time.Duration // The callback to be called whenever the internal state changes OnStateChange StateChangeCallback // The callback to be called on counter reset OnCountReset ResetCallback // This determines if a task is success or not, based on the returned error. // By default, all errors returned from the task indicate a failed task. IsSuccess IsSuccessCallback // This callback is used to determine when a Closed circuit should transitions to Open state. // By default, it should breaks the circuit when the number of failed attempts reaches 5. // Runs only when the task returns an error ShouldBreakCircuit Breaker }
type ResetCallback ¶
type ResetCallback func(stats Statistics, reason ResetReason)
type ResetReason ¶
type ResetReason struct {
// contains filtered or unexported fields
}
Contains the reason for a reset in the breaker's internal counter
func NewResetReason ¶
func NewResetReason(r string) ResetReason
type StateChangeCallback ¶
Click to show internal directories.
Click to hide internal directories.