retry

package
v0.0.0-...-1c5d739 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 2 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loop

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

Loop is an object that manages running the callable function and retrying it based on a give policy.

func NewLoop

func NewLoop(policy Policy, cancelable func(chan chan error) chan error) Loop

NewLoop creates a loop object that executes the cancelable function according to the given policy

func (Loop) Close

func (loop Loop) Close() error

Close stops the loop construct from attempting retries and notifies the running function to shutdown

func (Loop) Wait

func (loop Loop) Wait() error

Wait blocks until the loop exits

type Policy

type Policy interface {
	Name() string
	AllowRetry(retryCount int, elapsed time.Duration) (bool, time.Duration)
}

Policy is the interface for a retry policy type.

func BoundedExponentialBackoff

func BoundedExponentialBackoff(baseSleepTime time.Duration, maxSleepTime time.Duration, maxRetries int) Policy

BoundedExponentialBackoff returns a policy that will retry up to maxRetries with an exponentially increasing sleep time up to maxSleepTime.

func ExponentialBackoff

func ExponentialBackoff(baseSleepTime time.Duration, maxRetries int) Policy

ExponentialBackoff returns a policy that will retry up to maxRetries with an exponentially increasing sleep time.

func NTimes

func NTimes(n int, sleepBetweenRetries time.Duration) Policy

NTimes returns a retry policy that retries up to n times.

func Once

func Once(sleepBetweenRetry time.Duration) Policy

Once returns a policy that retries only once.

func UntilElapsed

func UntilElapsed(maxElapsed, sleepBetweenRetries time.Duration) Policy

UntilElapsed returns a policy that retries until a given amount of time elapses

Jump to

Keyboard shortcuts

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