shared

package
v0.0.0-...-3a98d3a Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ExtremeOpts gives an even longer timeout and more retries (~30 min).
	ExtremeOpts = Options{BaseDelay: 120 * time.Second, BackoffBase: 2.0, Retries: 10}
	// LongerOpts gives a longer timeout than default (~7.5 minutes).
	LongerOpts = Options{BaseDelay: 30 * time.Second, BackoffBase: 2.0, Retries: 5}
	// DefaultOpts is the default timeout (~5 minutes).
	DefaultOpts = Options{BaseDelay: 10 * time.Second, BackoffBase: 2.0, Retries: 5}
	// ShortOpts is for operations that need rapid results.
	ShortOpts = Options{BaseDelay: 500 * time.Millisecond, BackoffBase: 1.0, Retries: 1}
	// NoRetryOpts is for unretriable requests or testing.
	NoRetryOpts = Options{BaseDelay: 0 * time.Second, BackoffBase: 1.0, Retries: 0}
)
View Source
var (
	ErrObjectNotExist = errors.New("object doesn't exist")
)

Functions

func DoWithRetry

func DoWithRetry(ctx context.Context, retryOpts Options, doFunc DoFunc) error

DoWithRetry executes function doFunc. If there is an error, it will retry with a backoff delay until max retry times reached or context done. If retryOpts.Retries == 0, it will execute doFunc just once without any retries. If retryOpts.Retries < 0, it retries an infinite number of times.

Types

type DoFunc

type DoFunc func() error

DoFunc is a function type that can be retried by DoWithRetry if the return error is not nil.

type Options

type Options struct {
	BaseDelay   time.Duration // backoff base delay.
	BackoffBase float64       // base for exponential backoff
	Retries     int           // allowed number of retries.
}

Options wraps retry options.

Jump to

Keyboard shortcuts

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