retry

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBackOffConfig = BackOffConfig{
	MaxDelay:  120 * time.Second,
	BaseDelay: 1.0 * time.Second,
	Factor:    1.6,
	Jitter:    0.2,
}

Functions

func WithRetry

func WithRetry(retries int, backOff BackOffConfig, taskFn func() error) error

WithRetry: support backOff

func WithSimpleRetry

func WithSimpleRetry(retries int, taskFn func() error) error

WithRetry: support backOff, 自动重试, 支持回退策略

Types

type BackOff

type BackOff interface {
	// BackOff returns the amount of time to wait before the next retry given
	// the number of consecutive failures.
	BackOff(retries int) time.Duration
}

BackOff defines the methodology for backing off after a call failure.

type BackOffConfig

type BackOffConfig struct {
	// MaxDelay is the upper bound of BackOff delay.
	MaxDelay time.Duration

	// baseDelay is the amount of time to wait before retrying after the first
	// failure.
	BaseDelay time.Duration

	// factor is applied to the BackOff after each retry.
	Factor float64

	// jitter provides a range to randomize BackOff delays.
	Jitter float64
}

BackOffConfig defines the parameters for the default BackOff strategy.

func (*BackOffConfig) BackOff

func (bc *BackOffConfig) BackOff(retries int) time.Duration

BackOff returns the amount of time to wait before the next retry given the number of consecutive failures.

Jump to

Keyboard shortcuts

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