retry

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ConfigInitialDelay = "initialDelay"
	ConfigMaximumDelay = "maxDelay"
	ConfigFactor       = "factor"
)

Variables

This section is empty.

Functions

func InitConfig added in v1.4.0

func InitConfig(conf config.Section)

Types

type Retry

type Retry struct {
	InitialDelay time.Duration   `ffstruct:"RetryConfig" json:"initialDelay,omitempty"`
	MaximumDelay time.Duration   `ffstruct:"RetryConfig" json:"maximumDelay,omitempty"`
	Factor       float64         `ffstruct:"RetryConfig" json:"factor,omitempty"`
	ErrCallback  func(err error) `json:"-"`
}

Retry is a concurrency safe retry structure that configures a simple backoff retry mechanism. Can be loaded directly from JSON/YAML config

func NewFromConfig added in v1.4.0

func NewFromConfig(conf config.Section) *Retry

func (*Retry) Do

func (r *Retry) Do(ctx context.Context, logDescription string, f func(attempt int) (retry bool, err error)) error

Do invokes the function until the function returns false, or the retry pops. This simple interface doesn't pass through errors or return values, on the basis you'll be using a closure for that.

func (*Retry) DoCustomLog

func (r *Retry) DoCustomLog(ctx context.Context, f func(attempt int) (retry bool, err error)) error

DoCustomLog disables the automatic attempt logging, so the caller should do logging for each attempt

Jump to

Keyboard shortcuts

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