circuitbreaker

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCircuitOpen is returned when the circuit breaker is open
	ErrCircuitOpen = errors.New("circuit breaker is open")
)

Functions

This section is empty.

Types

type CircuitBreaker

type CircuitBreaker struct {
	// contains filtered or unexported fields
}

CircuitBreaker represents a circuit breaker instance with its configuration and state.

func NewCircuitBreaker

func NewCircuitBreaker(config Config, logger *zap.Logger, registry *prometheus.Registry) (*CircuitBreaker, error)

NewCircuitBreaker creates a new CircuitBreaker instance and configures it with the provided settings. It returns the configured CircuitBreaker instance and any error that occurred during initialization.

func (*CircuitBreaker) Counts added in v0.0.13

func (cb *CircuitBreaker) Counts() gobreaker.Counts

Counts returns the current counts of the circuit breaker.

func (*CircuitBreaker) Execute

func (cb *CircuitBreaker) Execute(operation func() error) error

Execute executes a function within the circuit breaker. It returns any error that occurred during execution.

func (*CircuitBreaker) State added in v0.0.13

func (cb *CircuitBreaker) State() gobreaker.State

State returns the current state of the circuit breaker.

type Config

type Config struct {
	// Name is the unique identifier for the circuit breaker.
	Name string
	// MaxRequests is the maximum number of requests allowed within the Interval.
	MaxRequests uint32
	// Interval is the time window for measuring the number of requests.
	Interval time.Duration
	// Timeout is the time limit for a single request.
	Timeout time.Duration
	// FailureThreshold is the number of consecutive failures required to trip the circuit breaker.
	FailureThreshold uint32
	// TestMode indicates whether the circuit breaker is running in test mode.
	TestMode bool
}

Config represents the configuration settings for a CircuitBreaker instance.

Jump to

Keyboard shortcuts

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