resilience

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBackoff = Backoff{
	Base:       100 * time.Millisecond,
	Max:        30 * time.Second,
	Multiplier: 2.0,
	Jitter:     true,
}
View Source
var DefaultRetry = RetryConfig{
	MaxAttempts: 3,
	Backoff:     DefaultBackoff,
}
View Source
var ErrCircuitOpen = errors.New("circuit breaker is open")

Functions

func Retry

func Retry(ctx context.Context, cfg RetryConfig, fn func() error) error

Retry calls fn repeatedly until it succeeds or runs out of attempts.

Types

type Backoff

type Backoff struct {
	Base       time.Duration
	Max        time.Duration
	Multiplier float64
	Jitter     bool
}

Backoff calculates how long to wait before the next retry.

func (Backoff) Duration

func (b Backoff) Duration(n int) time.Duration

type CircuitBreaker

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

CircuitBreaker stops calling a failing service to give it time to recover.

func NewCircuitBreaker

func NewCircuitBreaker(maxFailures int, timeout time.Duration) *CircuitBreaker

func (*CircuitBreaker) Execute

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

Execute runs fn if the circuit allows it. In half-open state only one trial request is allowed at a time.

type RetryConfig

type RetryConfig struct {
	MaxAttempts int
	Backoff     Backoff
}

RetryConfig controls how retries behave.

Jump to

Keyboard shortcuts

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