Documentation
¶
Index ¶
Constants ¶
View Source
const ( DefaultFailureThreshold = 5 DefaultRecoveryThreshold = 3 DefaultTestRequestsAllowed = 3 DefaultResetTimeout = 5 * time.Second DefaultFailureResetInterval = 60 * time.Second )
Variables ¶
View Source
var ( ErrorCircuitOpen = errors.New("circuit breaker is open") ErrorCircuitHalfOpenAllowedRequests = errors.New("circuit breaker half open test requests exhausted") )
Functions ¶
This section is empty.
Types ¶
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
func NewCircuitBreaker ¶
func NewCircuitBreaker(opts Options) *CircuitBreaker
func (*CircuitBreaker) Execute ¶
func (cb *CircuitBreaker) Execute(action func() error) error
Execute runs the action and returns an error if the circuit breaker is open
type Options ¶
type Options struct {
// Number of failed requests required to set the state to open
FailureThreshold int
// Number of successful requests required to set the state to closed
RecoveryThreshold int
// Number of concurrent test requests allowed in half open state
TestRequestsAllowed int
// Timeout for open state after which the state is set to half open
ResetTimeout time.Duration
// Interval after which the failure count is reset
FailureResetInterval time.Duration
}
Click to show internal directories.
Click to hide internal directories.