resilience

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package resilience provides circuit breakers and bounded concurrency.

Index

Constants

This section is empty.

Variables

View Source
var ErrBulkheadFull = errors.New("resilience: bulkhead queue full")
View Source
var ErrOpen = errors.New("resilience: circuit open")

Functions

This section is empty.

Types

type Breaker

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

Breaker coordinates concurrency-safe circuit-breaker state.

func New

func New(c Config) (*Breaker, error)

New constructs and validates an explicitly owned instance. See package documentation for defaults and cleanup.

func (*Breaker) Do

func (b *Breaker) Do(ctx context.Context, fn func(context.Context) error) (result error)

Do executes the supplied operation with this component's context and policy.

func (*Breaker) Stats

func (b *Breaker) Stats() Stats

Stats returns a concurrency-safe statistics snapshot.

type Bulkhead

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

Bulkhead bounds concurrency and memory attributable to queued admissions.

func NewBulkhead

func NewBulkhead(n int) (*Bulkhead, error)

NewBulkhead preserves cancellable waiting with a finite default queue of 1024 operations.

func NewBulkheadWithConfig

func NewBulkheadWithConfig(c BulkheadConfig) (*Bulkhead, error)

NewBulkheadWithConfig validates and creates an independently usable admission policy.

func (*Bulkhead) Do

func (b *Bulkhead) Do(ctx context.Context, fn func(context.Context) error) (result error)

Do executes an operation after bounded admission. Context cancellation interrupts queued waiting.

func (*Bulkhead) Stats

func (b *Bulkhead) Stats() BulkheadStats

Stats is a concurrency-safe observational snapshot; current counters may change immediately after return.

type BulkheadConfig

type BulkheadConfig struct {
	Concurrency, Queue int
	Observer           instrument.Hook
}

BulkheadConfig bounds both executing operations and admitted waiters. Zero Queue means no waiting.

type BulkheadStats

type BulkheadStats struct{ Active, Queued, Completed, Rejected int64 }

BulkheadStats exposes cumulative completion/rejection and current execution/queue counters.

type Config

type Config struct {
	Observer                                          instrument.Hook
	FailureThreshold, MinimumRequests, HalfOpenProbes int
	FailureRate                                       float64
	Recovery                                          time.Duration
	OnChange                                          func(State, State)
	Failure                                           func(error) bool
}

Config contains explicit constructor settings; see package documentation for defaults.

type State

type State string

State identifies a processing or circuit-breaker state.

const (
	Closed   State = "closed"
	Open     State = "open"
	HalfOpen State = "half_open"
)

type Stats

type Stats struct {
	State                        State
	Requests, Failures, InFlight int
	Generation                   uint64
}

Stats contains a snapshot of operational counters.

Jump to

Keyboard shortcuts

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