restrix

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 7 Imported by: 0

README

restrix

Prerequisite

  • Redis v7 or higher

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCircuitOpened = errors.New("restrix: circuit opened")
)

Functions

This section is empty.

Types

type Breaker

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

Breaker object

func NewBreaker

func NewBreaker(redisPool *redis.Pool) *Breaker

NewBreaker with default settings

func NewBreakerWithCustomSettings

func NewBreakerWithCustomSettings(redisPool *redis.Pool, settings CircuitSettings) *Breaker

NewBreakerWithCustomSettings instantiate a new breaker with custom settings

func (Breaker) Do

func (b Breaker) Do(name string, runFn func() error) error

Do invoke function with breaker without context

func (Breaker) DoCtx

func (b Breaker) DoCtx(ctx context.Context, name string, runFnCtx func(ctx context.Context) error) error

DoCtx invoke function with breaker with context

type CircuitSettings

type CircuitSettings struct {
	// RequestCountThreshold is the minimum number of requests needed cbefore a circuit can be tripped due to health
	RequestCountThreshold int `json:"request_volume_threshold"`

	// SleepWindow is how long to wait after a circuit opens before testing for recovery
	SleepWindow time.Duration `json:"sleep_window"`

	// ErrorPercentThreshold causes circuits to open once the rolling measure of errors exceeds this percent of requests
	ErrorPercentThreshold int `json:"error_percent_threshold"`

	// Interval which error percentage is calculated
	Interval time.Duration `json:"interval"`
}

CircuitSettings is used to tune circuit settings at runtime

Jump to

Keyboard shortcuts

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