retry

package
v0.0.0-...-4cb4cf9 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// With 5 attempts (4 retries) and a backoff factor of 2 seconds the total time spent retrying will be approximately:
	// 1 + 4 + 8 + 16 = 31 seconds.
	DefaultDownloadBackoffBase   = 2.0
	DefaultDownloadRetryAttempts = 5
	DefaultDownloadRetryDuration = time.Second
)

Variables

This section is empty.

Functions

func Run

func Run(function func() error, attempts int, sleep time.Duration) (err error)

Run runs function up to 'attempts' times, waiting i * sleep duration before each i-th attempt.

func RunWithDefaultDownloadBackoff

func RunWithDefaultDownloadBackoff(function func() error, cancel <-chan struct{}) (wasCancelled bool, err error)

RunWithDefaultDownloadBackoff runs function up to 'DefaultDownloadRetryAttempts' times, waiting 'DefaultDownloadBackoffBase^(i-1)' seconds before each i-th attempt. An optional cancel channel can be provided to cancel the retry loop immediately by closing the channel.

The function is meant as a default for network download operations.

func RunWithExpBackoff

func RunWithExpBackoff(function func() error, attempts int, sleep time.Duration, backoffExponentBase float64, cancel <-chan struct{}) (wasCancelled bool, err error)

RunWithExpBackoff runs function up to 'attempts' times, waiting 'backoffExponentBase^(i-1) * sleep' duration before each i-th attempt. An optional cancel channel can be provided to cancel the retry loop immediately by closing the channel.

func RunWithLinearBackoff

func RunWithLinearBackoff(function func() error, attempts int, sleep time.Duration, cancel <-chan struct{}) (wasCancelled bool, err error)

RunWithLinearBackoff runs function up to 'attempts' times, waiting i * sleep duration before each i-th attempt. An optional cancel channel can be provided to cancel the retry loop immediately by closing the channel.

Types

This section is empty.

Jump to

Keyboard shortcuts

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