retry

package
v1.10.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2021 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Jitter

type Jitter func(baseTime time.Duration) time.Duration

Jitter should return a new wait duration optionally with some time added or removed to create some randomness in wait time.

func NewJitter

func NewJitter(percent int64) Jitter

NewJitter returns a new random Jitter that is up to percent longer than the original wait time.

type Waiter

type Waiter struct {
	// MinFailures before exponential backoff starts. Any failures before
	// MinFailures is reached will wait MinWait time.
	MinFailures uint
	// MinWait time. Returned after the first failure.
	MinWait time.Duration
	// MaxWait time applied before Jitter. Note that the actual maximum wait time
	// is MaxWait + MaxWait * Jitter.
	MaxWait time.Duration
	// Jitter to add to each wait time. The Jitter is applied after MaxWait, which
	// may cause the actual wait time to exceed MaxWait.
	Jitter Jitter
	// Factor is the multiplier to use when calculating the delay. Defaults to
	// 1 second.
	Factor time.Duration
	// contains filtered or unexported fields
}

Waiter records the number of failures and performs exponential backoff when when there are consecutive failures.

func (*Waiter) Failures

func (w *Waiter) Failures() int

Failures returns the count of consecutive failures.

func (*Waiter) Reset

func (w *Waiter) Reset()

Reset the failure count to 0.

func (*Waiter) Wait

func (w *Waiter) Wait(ctx context.Context) error

Wait increase the number of failures by one, and then blocks until the context is cancelled, or until the wait time is reached. The wait time increases exponentially as the number of failures increases. Wait will return ctx.Err() if the context is cancelled.

Jump to

Keyboard shortcuts

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