circuitbreaker

package
v0.0.0-...-e15a062 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: CC0-1.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCircuitOpen = errors.New("circuit breaker is open")

Functions

This section is empty.

Types

type Breaker

type Breaker interface {
	Allow(ctx context.Context) error
	OnSuccess(ctx context.Context)
	OnFailure(ctx context.Context)
}

type Options

type Options struct {
	// Number of failures before entering open state.
	FailureThreshold int
	// Time between failures to count as an outage.
	FailWindow time.Duration
	// How long to stay in open state before triggering half-open state.
	OpenCoolDown time.Duration
	// Time lease to allow only one pod instance at a time to test whether the circuit can be reopened.
	HalfOpenLease time.Duration
	// If Redis is unreachable (down, unavailable, timing out) and it's state is unknown, this determines the default behavior of the Allow method. What to do while breaker is blind.
	// TRUE: allows requests to proceed without circuit breaker participating
	// FALSE: blocks requests
	FailOpen bool
	// Key prefix to prevent name clashing.
	Prefix string
}

func DefaultOptions

func DefaultOptions() Options

type RedisBreaker

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

func NewRedisBreaker

func NewRedisBreaker(rdb *redis.Client, name string, opts Options, logger *slog.Logger) *RedisBreaker

func (*RedisBreaker) Allow

func (b *RedisBreaker) Allow(ctx context.Context) error

func (*RedisBreaker) OnFailure

func (b *RedisBreaker) OnFailure(ctx context.Context)

func (*RedisBreaker) OnSuccess

func (b *RedisBreaker) OnSuccess(ctx context.Context)

Jump to

Keyboard shortcuts

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