circuitbreaker

package
v0.0.0-...-d386c04 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTooManyRequests is returned when the CB state is half open and the requests count is over the cb maxRequests
	ErrTooManyRequests = errors.New("INFRASTRUCTURE.CIRCUIT_BREAKER.STAGE_HALF_OPEN.TOO_MANY_REQUESTS.ERROR")
	// ErrOpenState is returned when the CB state is open
	ErrOpenState   = errors.New("INFRASTRUCTURE.CIRCUIT_BREAKER.STAGE_OPEN.OPENED.ERROR")
	ErrStageChange = errors.New("INFRASTRUCTURE.CIRCUIT_BREAKER.STAGE.CHANGE.ERROR")
)
View Source
var DefaultConfig = &Config{
	Close: Close{CleanupInterval: 600000},
	Half:  Half{PassthroughRequests: 10},
	Open: Open{
		Duration:   1800000,
		Conditions: OpenConditions{ErrorConsecutive: 10, ErrorRatio: 0.5},
	},
}

Functions

func Do

func Do[T any](cb CircuitBreaker, cmd string, onHandle Handler, onError ErrorHandler) (*T, error)

Types

type CircuitBreaker

type CircuitBreaker interface {
	Do(cmd string, onHandle Handler, onError ErrorHandler) (any, error)
}

func New

func New(conf *Config, logger logging.Logger) (CircuitBreaker, error)

func NewSony

func NewSony(conf *Config, logger logging.Logger) (CircuitBreaker, error)

type Close

type Close struct {
	CleanupInterval int `json:"cleanup_interval" yaml:"cleanup_interval" mapstructure:"cleanup_interval"`
}

func (*Close) Validate

func (conf *Close) Validate() error

type Config

type Config struct {
	Close Close `json:"close" yaml:"close" mapstructure:"close"`
	Half  Half  `json:"half" yaml:"half" mapstructure:"half"`
	Open  Open  `json:"open" yaml:"open" mapstructure:"open"`
}

func (*Config) Validate

func (conf *Config) Validate() error

type ErrorHandler

type ErrorHandler func(err error) error

type Half

type Half struct {
	PassthroughRequests uint32 `json:"passthrough_requests" yaml:"passthrough_requests" mapstructure:"passthrough_requests"`
}

func (*Half) Validate

func (conf *Half) Validate() error

type Handler

type Handler func() (any, error)

type Open

type Open struct {
	Duration   int64          `json:"duration" yaml:"duration" mapstructure:"duration"`
	Conditions OpenConditions `json:"conditions" yaml:"conditions" mapstructure:"conditions"`
}

func (*Open) Validate

func (conf *Open) Validate() error

type OpenConditions

type OpenConditions struct {
	ErrorConsecutive uint32  `json:"error_consecutive" yaml:"error_consecutive" mapstructure:"error_consecutive"`
	ErrorRatio       float32 `json:"error_ratio" yaml:"error_ratio" mapstructure:"error_ratio"`
}

func (*OpenConditions) Validate

func (conf *OpenConditions) Validate() error

Jump to

Keyboard shortcuts

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