breaker

package
v1.10.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOpenState       = gobreaker.ErrOpenState
	ErrTooManyRequests = gobreaker.ErrTooManyRequests
)

Functions

func IsErrorPermanent

func IsErrorPermanent(err error) bool

IsErrorPermanent returns true if `err` should be treated as a permanent error that cannot be retried.

Types

type CircuitBreaker

type CircuitBreaker struct {
	// Name is the circuit breaker name.
	Name string
	// The maximum number of requests allowed to pass through when
	// the circuit breaker is half-open.
	// Default is 1.
	MaxRequests uint32 `mapstructure:"maxRequests"`
	// The cyclic period of the closed state for the circuit breaker
	// to clear the internal counts. If 0, the circuit breaker doesn't
	// clear internal counts during the closed state.
	// Default is 0s.
	Interval time.Duration `mapstructure:"interval"`
	// The period of the open state, after which the state of the
	// circuit breaker becomes half-open.
	// Default is 60s.
	Timeout time.Duration `mapstructure:"timeout"`
	// Trip is a CEL expression evaluated with the circuit breaker's
	// internal counts whenever a request fails in the closed state.
	// If it evaluates to true, the circuit breaker will be placed
	// into the open state.
	// Default is consecutiveFailures > 5.
	Trip *expr.Expr `mapstructure:"trip"`
	// contains filtered or unexported fields
}

CircuitBreaker represents the configuration for how a circuit breaker behaves.

func (*CircuitBreaker) Execute

func (c *CircuitBreaker) Execute(oper func() (any, error)) (any, error)

Execute invokes `oper` if the circuit breaker is in an closed state or for an allowed call in the half-open state. It is a wrapper around the gobreaker library that is used here. The circuit breaker shorts if the connection is in open state or if there are too many requests in the half-open state. In both cases, the error returned is wrapped with ErrOpenState or ErrTooManyRequests defined in this package. The result of the operation in those scenarios will by nil/zero. In all other scenarios the result, error returned is the result, error returned by the operation.

func (*CircuitBreaker) Initialize

func (c *CircuitBreaker) Initialize(log logger.Logger)

Initialize creates the underlying circuit breaker using the configuration fields.

func (CircuitBreaker) String added in v1.10.0

func (c CircuitBreaker) String() string

String implements fmt.Stringer and is used for debugging.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL