backoffs

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2018 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeConstant    = "constant"
	TypeLinear      = "linear"
	TypeExponential = "exponential"
)
View Source
const DefaultInterval = 10
View Source
const DefaultMultiplier = 2

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

type Backoff interface {
	Init() time.Duration
	Next(failCount int) time.Duration
}

func New

func New(cfg Config) Backoff

Creates new Backoff instance based on provided configuration

type Config

type Config struct {
	Type       string `json:"type"`
	Interval   *int   `json:"interval"`
	Multiplier *int   `json:"multiplier,omitempty"`
}

type Constant

type Constant struct {
	Interval int
}

func NewConstant

func NewConstant(interval int) *Constant

Constant backoff has always the same interval

func (*Constant) Init

func (b *Constant) Init() time.Duration

Returns initial interval

func (*Constant) Next

func (b *Constant) Next(failCount int) time.Duration

Returns next interval based on failed requests count

type Exponential

type Exponential struct {
	Interval   int
	Multiplier int
}

func NewExponential

func NewExponential(interval int, multiplier *int) *Exponential

Exponential backoff provides a backoff implementation where the next delay upon failure is a multiplier of the previous delay

func (*Exponential) Init

func (b *Exponential) Init() time.Duration

Returns initial interval

func (*Exponential) Next

func (b *Exponential) Next(failCountInt int) time.Duration

Returns next interval based on failed requests count

type Linear

type Linear struct {
	Interval int
}

func NewLinear

func NewLinear(interval int) *Linear

Linear backoff multiplies initial interval by failed request count

func (*Linear) Init

func (b *Linear) Init() time.Duration

Returns initial interval

func (*Linear) Next

func (b *Linear) Next(failCount int) time.Duration

Returns next interval based on failed requests count

Jump to

Keyboard shortcuts

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