circuit

package module
v0.0.0-...-eb0af4f Latest Latest
Warning

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

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

Documentation

Overview

package circuit is an alternative of the classic circuitbreaker.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnavailable = errors.New("circuit: unavailable")
	ErrForcedOpen  = errors.New("circuit: forced open")
)

Functions

This section is empty.

Types

type Breaker

type Breaker struct {

	// Options.
	FailureCount  func(error) int
	Now           func() time.Time
	SlowCallCount func(time.Duration) int
	// contains filtered or unexported fields
}

func New

func New(client *redis.Client, channel string, opts *Options) (*Breaker, func())

func (*Breaker) Do

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

func (*Breaker) Status

func (b *Breaker) Status() Status

type Options

type Options struct {
	BreakDuration     time.Duration
	FailureRatio      float64
	FailureThreshold  int
	HeartbeatDuration time.Duration
	SamplingDuration  time.Duration
	SuccessThreshold  int
}

func NewOptions

func NewOptions() *Options

type Status

type Status int
const (
	Closed Status = iota
	Disabled
	HalfOpen
	ForcedOpen
	Open
)

func NewStatus

func NewStatus(status string) Status

func (Status) String

func (s Status) String() string

Jump to

Keyboard shortcuts

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