backoff

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = FiveSec

Default is the default backoff policy to use

View Source
var FiveSec = Policy{
	Millis: []int{500, 750, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000},
}

FiveSec is a backoff policy ranging up to 5 seconds.

View Source
var FiveSecStartGrace = Policy{
	Millis: []int{0, 25, 50, 75, 100, 125, 150, 200, 250, 500, 750, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000},
}

FiveSecStartGrace Like FiveSec but allows for a few fairly rapid initial tries

View Source
var TwentySec = Policy{
	Millis: []int{
		500, 750, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000,
		5500, 5750, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000,
		10500, 10750, 11000, 11500, 12000, 12500, 13000, 13500, 14000, 14500, 15000,
		15500, 15750, 16000, 16500, 17000, 17500, 18000, 18500, 19000, 19500, 20000,
	},
}

TwentySec is a backoff policy ranging up to 20 seconds

View Source
var TwoMinutesSlowStart = Policy{
	Millis: []int{
		6000, 12000, 18000, 24000, 30000, 36000, 42000, 48000, 54000, 60000,
		66000, 72000, 78000, 84000, 90000, 96000, 102000, 108000,
	},
}

TwoMinutesSlowStart is a backoff policy ranging from 6 seconds to 120 seconds over 18 intervals

Functions

func Sleep

func Sleep(ctx context.Context, t time.Duration) error

Sleep sleeps for the duration t and can be interrupted by ctx. An error is returns if the context cancels the sleep

Types

type Policy

type Policy struct {
	Millis []int
}

Policy implements a backoff policy, randomizing its delays and saturating at the final value in Millis.

func (Policy) Duration

func (b Policy) Duration(n int) time.Duration

Duration returns the time duration of the n'th wait cycle in a backoff policy. This is b.Millis[n], randomized to avoid thundering herds.

func (Policy) For

func (b Policy) For(ctx context.Context, cb func(try int) error) error

For is a for{} loop that stops on context and has a backoff based sleep between loops if the context completes the loop ends returning the context error

func (Policy) Sleep

func (b Policy) Sleep(ctx context.Context, t time.Duration) error

Sleep sleeps for the duration t and can be interrupted by ctx. An error is returns if the context cancels the sleep

func (Policy) TrySleep

func (b Policy) TrySleep(ctx context.Context, n int) error

TrySleep sleeps for the duration of the n'th try cycle in a way that can be interrupted by the context. An error is returned if the context cancels the sleep

Jump to

Keyboard shortcuts

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