backoff

package
v0.0.0-...-5655933 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Policy

type Policy struct {
	// MinBackoffFactor controls the overlap between consecutive retry interval ranges. When
	// set to `2`, there is a guarantee that there will be no overlap. The overlap
	// will asymptotically approach 50% the higher the value is set.
	MinBackoffFactor float64

	// BaseBackoffTime controls the rate of exponential growth. Also, you can calculate the start
	// of the very first retry interval range by evaluating the following expression:
	// baseBackoffTime / minBackoffFactor * 2
	BaseBackoffTime float64

	// MaxBackoffTime is the maximum number of seconds to wait for a retry.
	MaxBackoffTime float64

	// RecoveryInterval controls how many retry interval ranges to step down for an endpoint
	// upon success. Increasing this should only be considered when maxBackoffTime
	// is particularly high or if our intake team is particularly confident.
	RecoveryInterval int

	// MaxErrors derived value is the number of errors it will take to reach the maxBackoffTime.
	MaxErrors int
}

Policy contains parameters and logic necessary to implement an exponential backoff strategy when handling errors.

func NewPolicy

func NewPolicy(minBackoffFactor, baseBackoffTime, maxBackoffTime float64, recoveryInterval int, recoveryReset bool) Policy

NewPolicy constructs new Backoff object with given parameters

func (*Policy) DecError

func (b *Policy) DecError(numErrors int) int

DecError decrements the error counter down to zero at RecoveryInterval rate

func (*Policy) GetBackoffDuration

func (b *Policy) GetBackoffDuration(numErrors int) time.Duration

GetBackoffDuration returns amount of time to sleep after numErrors error

func (*Policy) IncError

func (b *Policy) IncError(numErrors int) int

IncError increments the error counter up to MaxErrors

Jump to

Keyboard shortcuts

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