backoff

package
Version: v0.0.0-...-24d4c76 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2018 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomTimer

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

CustomTimer represents a backoff timer configured with a certain DelayProvider.

func NewCustomTimer

func NewCustomTimer(delayProvider DelayProvider) *CustomTimer

NewCustomTimer creates a new custom timer using the provided delay provider.

func (*CustomTimer) Close

func (t *CustomTimer) Close()

Close cleans up the resources used by this timer. It cannot be reused after this call.

func (*CustomTimer) CurrentDelay

func (t *CustomTimer) CurrentDelay() time.Duration

CurrentDelay returns the delay of the current or last ticked retry.

func (*CustomTimer) NumRetries

func (t *CustomTimer) NumRetries() int

NumRetries returns the number of tries since this timer was last reset.

func (*CustomTimer) ReceiveTick

func (t *CustomTimer) ReceiveTick() <-chan time.Time

ReceiveTick returns a channel that will receive a time.Time object as soon as the previously scheduled retry ticks.

func (*CustomTimer) Reset

func (t *CustomTimer) Reset()

Reset stops and resets the number of retries counter of this timer.

func (*CustomTimer) ScheduleRetry

func (t *CustomTimer) ScheduleRetry(err error) (int, time.Duration)

ScheduleRetry schedules the next retry tick according to the delay provider, returning retry num and retry delay.

func (*CustomTimer) Stop

func (t *CustomTimer) Stop()

Stop prevents any current scheduled retry from ticking.

type DelayProvider

type DelayProvider func(numRetries int, err error) time.Duration

DelayProvider is a function that takes the current numRetries and last error and returns the delay until next retry.

func DefaultExponentialDelayProvider

func DefaultExponentialDelayProvider() DelayProvider

DefaultExponentialDelayProvider creates a new instance of an ExponentialDelayProvider using the default config.

func ExponentialDelayProvider

func ExponentialDelayProvider(conf ExponentialConfig) DelayProvider

ExponentialDelayProvider creates a new instance of an ExponentialDelayProvider using the provided config.

type ExponentialConfig

type ExponentialConfig struct {
	MaxDuration time.Duration
	GrowthBase  int
	Base        time.Duration
}

ExponentialConfig holds the parameters used by the ExponentialTimer.

func DefaultExponentialConfig

func DefaultExponentialConfig() ExponentialConfig

DefaultExponentialConfig creates an ExponentialConfig with default values.

type ExponentialTimer

type ExponentialTimer struct {
	CustomTimer
}

ExponentialTimer performs an exponential backoff following the FullJitter implementation described in https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/

func NewCustomExponentialTimer

func NewCustomExponentialTimer(conf ExponentialConfig) *ExponentialTimer

NewCustomExponentialTimer creates an exponential backoff timer using the provided configuration.

func NewExponentialTimer

func NewExponentialTimer() *ExponentialTimer

NewExponentialTimer creates an exponential backoff timer using the default configuration.

type Timer

type Timer interface {
	ScheduleRetry(err error) (int, time.Duration)
	CurrentDelay() time.Duration
	NumRetries() int
	ReceiveTick() <-chan time.Time
	Reset()
	Stop()
}

Timer represents a timer that implements some backOff strategy that can adapt to number of schedulings.

Jump to

Keyboard shortcuts

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