retry

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: MIT Imports: 3 Imported by: 2

Documentation

Overview

Package retry is a wrapper around github.com/cenkalti/backoff that provides do-with-retry helper functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoWithRetry

func DoWithRetry(ctx context.Context, p Policy, isRetryable IsRetryable, notify backoff.Notify, fn RetryableFunc) error

DoWithRetry executes fn with retry according to policy p and with respect to context ctx. IsRetryable defines which errors lead to retry attempt (can be nil for any error). Notify can be used to receive notification on every retry with error and backoff delay (can be nil if no notifications required).

Types

type ConstantBackoffPolicy

type ConstantBackoffPolicy struct {
	// contains filtered or unexported fields
}

ConstantBackoffPolicy means repeat up to max times with constant interval delays.

func NewConstantBackoffPolicy

func NewConstantBackoffPolicy(interval time.Duration, maxRetryAttempts int) ConstantBackoffPolicy

NewConstantBackoffPolicy returns a constant backoff policy with given interval and max retry attempt count.

func (ConstantBackoffPolicy) NewBackOff

func (p ConstantBackoffPolicy) NewBackOff() backoff.BackOff

NewBackOff implements retry.Policy.

type ExponentialBackoffPolicy

type ExponentialBackoffPolicy struct {
	// contains filtered or unexported fields
}

ExponentialBackoffPolicy means repeat up to max times with exponentially growing delays (1.5 multiplier).

func NewExponentialBackoffPolicy

func NewExponentialBackoffPolicy(initialInterval time.Duration, maxRetryAttempts int) ExponentialBackoffPolicy

NewExponentialBackoffPolicy returns an exponential backoff policy with given initial interval and max retry attempt count.

func (ExponentialBackoffPolicy) NewBackOff

func (p ExponentialBackoffPolicy) NewBackOff() backoff.BackOff

NewBackOff implements retry.Policy.

type IsRetryable

type IsRetryable func(error) bool

IsRetryable defines a func that can tell if error is retryable as opposed to persistent.

type Policy

type Policy interface {
	NewBackOff() backoff.BackOff
}

Policy defines backoff strategy.

type PolicyFunc

type PolicyFunc func() backoff.BackOff

The PolicyFunc type is an adapter to allow the use of ordinary functions as retry.Policy.

func (PolicyFunc) NewBackOff

func (f PolicyFunc) NewBackOff() backoff.BackOff

NewBackOff implements retry.Policy.

type RetryableFunc

type RetryableFunc func(ctx context.Context) error

RetryableFunc is function that does some work and can be potentially retried.

Jump to

Keyboard shortcuts

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