retry

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const RetrierMaxDelayCoeff = 20

Variables

View Source
var ErrDeadlineExceeded = errors.New("deadline exceeded")
View Source
var ErrMaxAttemptsExceeded = errors.New("max attempts exceeded")

Functions

func Disable

func Disable(err error) error

func Retryable

func Retryable(err error) bool

Types

type Policy

type Policy struct {
	Attempts int           `json:"attempts,omitempty" yaml:"attempts,omitempty"` // The maximum number of retries.
	Backoff  util.Duration `json:"backoff,omitempty" yaml:"backoff,omitempty"`   // The base delay between retries.
	Timeout  util.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`   // The maximum time to wait for a retry.
}

func Basic

func Basic() Policy

func Long

func Long() Policy

func (Policy) MaxDelay added in v0.3.2

func (retry Policy) MaxDelay() time.Duration

func (Policy) Retrier

func (policy Policy) Retrier() Retrier

Creates a retries with the given policy

func (Policy) RetrierContext

func (policy Policy) RetrierContext(ctx context.Context) Retrier

Creates a retries with the given policy and context

func (Policy) Run

func (policy Policy) Run(f func() error) (err error)

Convenience function for running a function with a retry policy

func (Policy) RunContext

func (policy Policy) RunContext(ctx context.Context, f func() error) (err error)

Convenience function for running a function with a retry policy and context

func (Policy) Step

func (retry Policy) Step(step *int, delay *time.Duration) error

func (Policy) StepN added in v0.3.2

func (retry Policy) StepN(n int) (delay time.Duration, err error)

func (Policy) WithDefaults added in v0.3.2

func (retry Policy) WithDefaults() Policy

type Retrier

type Retrier struct {
	Context  context.Context
	Policy   Policy
	Step     int
	Delay    time.Duration
	Deadline time.Time
}

func (*Retrier) Consume

func (retry *Retrier) Consume(err error) error

func (*Retrier) ConsumeAny

func (retry *Retrier) ConsumeAny() error

Tries to consume the error, and if it can't returns the error

func (*Retrier) NextDelay

func (retry *Retrier) NextDelay() (delay time.Duration, err error)

Returns the next delay, or an error if the retries are exhausted

func (Retrier) Run

func (retry Retrier) Run(f func() error) (err error)

Runs the function until it succeeds or the retries are exhausted

Jump to

Keyboard shortcuts

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