breaker

package
v1.0.12-0...-16f252f Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrServiceUnavailable = errors.New("circuit breaker is open")

ErrServiceUnavailable is returned when the CB state is open

Functions

func Do

func Do(name string, req func() error) error

func DoWithAcceptable

func DoWithAcceptable(name string, req func() error, acceptable Acceptable) error

func DoWithFallback

func DoWithFallback(name string, req func() error, fallback func(err error) error) error

func DoWithFallbackAcceptable

func DoWithFallbackAcceptable(name string, req func() error, fallback func(err error) error,
	acceptable Acceptable) error

func NoBreakFor

func NoBreakFor(name string)

Types

type Acceptable

type Acceptable func(err error) bool

type Breaker

type Breaker interface {
	// Name returns the name of the netflixBreaker.
	Name() string

	// Allow checks if the request is allowed.
	// If allowed, a promise will be returned, the caller needs to call promise.Accept()
	// on success, or call promise.Reject() on failure.
	// If not allow, ErrServiceUnavailable will be returned.
	Allow() (Promise, error)

	// Do runs the given request if the netflixBreaker accepts it.
	// Do returns an error instantly if the netflixBreaker rejects the request.
	// If a panic occurs in the request, the netflixBreaker handles it as an error
	// and causes the same panic again.
	Do(req func() error) error

	// DoWithAcceptable runs the given request if the netflixBreaker accepts it.
	// Do returns an error instantly if the netflixBreaker rejects the request.
	// If a panic occurs in the request, the netflixBreaker handles it as an error
	// and causes the same panic again.
	// acceptable checks if it's a successful call, even if the err is not nil.
	DoWithAcceptable(req func() error, acceptable Acceptable) error

	// DoWithFallback runs the given request if the netflixBreaker accepts it.
	// DoWithFallback runs the fallback if the netflixBreaker rejects the request.
	// If a panic occurs in the request, the netflixBreaker handles it as an error
	// and causes the same panic again.
	DoWithFallback(req func() error, fallback func(err error) error) error

	// DoWithFallbackAcceptable runs the given request if the netflixBreaker accepts it.
	// DoWithFallback runs the fallback if the netflixBreaker rejects the request.
	// If a panic occurs in the request, the netflixBreaker handles it as an error
	// and causes the same panic again.
	// acceptable checks if it's a successful call, even if the err is not nil.
	DoWithFallbackAcceptable(req func() error, fallback func(err error) error, acceptable Acceptable) error
}

func GetBreaker

func GetBreaker(name string) Breaker

func NewBreaker

func NewBreaker(opts ...BreakerOption) Breaker

type BreakerOption

type BreakerOption func(breaker *circuitBreaker)

func WithName

func WithName(name string) BreakerOption

type Promise

type Promise interface {
	Accept()
	Reject(reason string)
}

type State

type State = int32
const (
	StateClosed State = iota
	StateOpen
)

Jump to

Keyboard shortcuts

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