retry

package
v0.0.0-...-c5b8800 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, operation Operation, opts ...Option) error

Do execute the specified function. By default, it retries infinitely until it succeeds or got canceled.

Types

type ErrorRetry

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

ErrorRetry is used to control the error retry logic.

func NewDefaultErrorRetry

func NewDefaultErrorRetry() *ErrorRetry

NewDefaultErrorRetry creates a new ErrorRetry with default values.

func NewErrorRetry

func NewErrorRetry(
	maxRetryDuration time.Duration,
	errGCInterval time.Duration,
	backoffBase int64,
	backoffMax int64,
) *ErrorRetry

NewErrorRetry creates a new ErrorRetry.

func NewInfiniteErrorRetry

func NewInfiniteErrorRetry() *ErrorRetry

NewInfiniteErrorRetry creates a new ErrorRetry with infinite duration.

func (*ErrorRetry) GetRetryBackoff

func (r *ErrorRetry) GetRetryBackoff(err error) (time.Duration, error)

GetRetryBackoff returns the backoff duration for retrying the last error. If the retry time is exhausted, it returns the an ChangefeedUnRetryableError.

type IsRetryable

type IsRetryable func(error) bool

IsRetryable checks the error is safe or worth to retry, eg. "context.Canceled" better not retry

type Operation

type Operation func() error

Operation is the action need to retry

type Option

type Option func(*retryOptions)

Option ...

func WithBackoffBaseDelay

func WithBackoffBaseDelay(delayInMs int64) Option

WithBackoffBaseDelay configures the initial delay, if delayInMs <= 0 "defaultBackoffBaseInMs" will be used

func WithBackoffMaxDelay

func WithBackoffMaxDelay(delayInMs int64) Option

WithBackoffMaxDelay configures the maximum delay, if delayInMs <= 0 "defaultBackoffCapInMs" will be used

func WithIsRetryableErr

func WithIsRetryableErr(f IsRetryable) Option

WithIsRetryableErr configures the error should retry or not, if not set, retry by default

func WithMaxTries

func WithMaxTries(tries uint64) Option

WithMaxTries configures maximum tries, if tries is 0, 1 will be used

func WithTotalRetryDuratoin

func WithTotalRetryDuratoin(retryDuration time.Duration) Option

WithTotalRetryDuratoin configures the total retry duration.

Jump to

Keyboard shortcuts

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