backoff

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package backoff implements a simple exponential backoff algorithms for retrying operations.

Use Do function for retrying operations that may fail.

Simple example:

boff := backoff.New(
	backoff.Exponential(),
	backoff.MaxRetries(30),
	backoff.Notify(func(err error, next time.Duration, count uint) {
		log.Println(count, next,  err)
	}),
)
err := boff.Do(ctx, func(ctx) error {
	// if fail
	return err
	// if fail but not retry
	return backoff.Continue(err)
	// if ok
	return nil
})

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMaxRetries     = errors.New("")
	ErrMaxElapsedTime = errors.New("")
)

Functions

func Continue

func Continue(err error) error

Types

type Backoff

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

func New

func New(opt ...Option) *Backoff

func (*Backoff) Do

func (this *Backoff) Do(ctx context.Context, fn Handle) error

type Handle

type Handle func(ctx context.Context) error

type NotifyHandle

type NotifyHandle func(err error, duration time.Duration, count uint)

type Option

type Option func(*internal.BackoffSettings)

func Exponential

func Exponential() Option

func Interval

func Interval(duration time.Duration) Option

func MaxElapsedTime

func MaxElapsedTime(duration time.Duration) Option

func MaxInterval

func MaxInterval(duration time.Duration) Option

func MaxRetries

func MaxRetries(v uint) Option

func Multiplier

func Multiplier(multiplier float64) Option

func Notify

func Notify(fn NotifyHandle) Option

func RandomizationFactor

func RandomizationFactor(randomizationFactor float64) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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