retry

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Clock = clock{
	Now:   time.Now,
	After: time.After,
}

Functions

This section is empty.

Types

type BackoffHandler

type BackoffHandler struct {
	// MaxRetries sets the maximum number of retries to perform. The default value
	// of 0 disables retry completely.
	MaxRetries uint
	// RetryForever caps the exponential backoff period according to MaxRetries
	// but allows you to retry indefinitely.
	RetryForever bool
	// BaseTime sets the initial backoff period.
	BaseTime time.Duration
	// contains filtered or unexported fields
}

BackoffHandler manages exponential backoff and limits the maximum number of retries. The base time period is 1 second, doubling with each retry. After initial success, a grace period can be set to reset the backoff timer if a connection is maintained successfully for a long enough period. The base grace period is 2 seconds, doubling with each retry.

func (*BackoffHandler) Backoff

func (b *BackoffHandler) Backoff(ctx context.Context) bool

Backoff is used to wait according to exponential backoff. Returns false if the maximum number of retries have been used or if the underlying context has been cancelled.

func (*BackoffHandler) BackoffTimer

func (b *BackoffHandler) BackoffTimer() <-chan time.Time

BackoffTimer returns a channel that sends the current time when the exponential backoff timeout expires. Returns nil if the maximum number of retries have been used.

func (BackoffHandler) GetBaseTime

func (b BackoffHandler) GetBaseTime() time.Duration

func (BackoffHandler) GetMaxBackoffDuration

func (b BackoffHandler) GetMaxBackoffDuration(ctx context.Context) (time.Duration, bool)

func (*BackoffHandler) ReachedMaxRetries

func (b *BackoffHandler) ReachedMaxRetries() bool

func (*BackoffHandler) ResetNow

func (b *BackoffHandler) ResetNow()

func (*BackoffHandler) Retries

func (b *BackoffHandler) Retries() int

Retries returns the number of retries consumed so far.

func (*BackoffHandler) SetGracePeriod

func (b *BackoffHandler) SetGracePeriod() time.Duration

Sets a grace period within which the the backoff timer is maintained. After the grace period expires, the number of retries & backoff duration is reset.

Jump to

Keyboard shortcuts

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