breaker

package
v0.0.0-...-c18a219 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Closed int32 = iota
	Open
	HalfOpen
)

Valid CircuitState values.

View Source
const PkgName = "auxo.apm.breaker"

Variables

View Source
var (
	// ErrMaxConcurrency occurs when too many of the same named command are executed at the same time.
	ErrMaxConcurrency = errors.New("breaker: max concurrency")
	// ErrCircuitOpen returns when an execution attempt "short circuits". This happens due to the circuit being measured as unhealthy.
	ErrCircuitOpen = errors.New("breaker: circuit open")
	// ErrTimeout occurs when the provided function takes too long to execute.
	ErrTimeout = errors.New("breaker: timeout")
)

Functions

This section is empty.

Types

type Action

type Action func() error

type Breaker

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

func NewBreaker

func NewBreaker(name string, cond Condition, opts Options) *Breaker

func (*Breaker) State

func (b *Breaker) State() int32

func (*Breaker) Summary

func (b *Breaker) Summary() Summary

func (*Breaker) Try

func (b *Breaker) Try(action Action, fallback ...Fallback) error

type Condition

type Condition func(c Counter) bool

Condition is a monitor for circuit, it return true if should open circuit.

func ConsecutiveErrorCount

func ConsecutiveErrorCount(count uint32) Condition

func ErrorCount

func ErrorCount(count uint32) Condition

func ErrorRate

func ErrorRate(rate float32, min uint32) Condition

type Counter

type Counter interface {
	Summary
	// Failure is consecutive failure count
	ConsecutiveFailure() uint32
}

type Fallback

type Fallback func(error) error

type Group

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

func NewGroup

func NewGroup() *Group

func (*Group) Get

func (g *Group) Get(name string, builder func() *Breaker) *Breaker

type Options

type Options struct {
	// Window is how long to wait for state switched to half-open from open.
	Window time.Duration
	// Timeout is how long to wait for action to complete.
	Timeout time.Duration
	// Concurrency is how many actions can execute at the same time. If concurrency is zero, no limitation is set.
	Concurrency int32
}

Options holds options of Breaker

type Summary

type Summary interface {
	// Total is total attempts
	Total() uint32
	// Success is success count
	Success() uint32
	// Failure is failure count
	Failure() uint32
	// Intercept is failure count with ErrCircuitOpen
	Intercept() uint32
	// Reject is failure count with ErrMaxConcurrency
	Reject() uint32
	// Timeout is failure count with ErrTimeout
	Timeout() uint32
	// FallbackSuccess is success count by fallback
	FallbackSuccess() uint32
	// FallbackFailure is failure count by fallback
	FallbackFailure() uint32
}

Summary represents statistics of Breaker.

Jump to

Keyboard shortcuts

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