retry

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Copyright (c) Microsoft Corporation. Licensed under the MIT License.

Copyright (c) Microsoft Corporation. Licensed under the MIT License.

Copyright (c) Microsoft Corporation. Licensed under the MIT License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExponentialBackoff

type ExponentialBackoff struct {
	// MaxAttempts sets the maximum number of attempts. The default value of 0
	// indicates unlimited attempts; setting this to 1 will disable retries.
	MaxAttempts uint64

	// MinInterval is the maximum interval between retries (before jitter).
	// Will be set to a default of 1/8s if unspecified.
	MinInterval time.Duration

	// MaxInterval is the maximum interval between retries (before jitter).
	// Will be set to a default of one minute if unspecified.
	MaxInterval time.Duration

	// Timeout is the total timeout for all retries.
	Timeout time.Duration

	// NoJitter removes the default jitter.
	NoJitter bool

	// Logger provides a logger which will be used to log retry attempts and
	// results.
	Logger *slog.Logger
}

ExponentialBackoff implements a retry policy with exponential backoff and optional jitter.

func (*ExponentialBackoff) Start

func (e *ExponentialBackoff) Start(
	ctx context.Context,
	name string,
	task Task,
) error

Start initiates the retry executions.

type Policy

type Policy interface {
	Start(ctx context.Context, name string, task Task) error
}

Policy is the retry policy for task execution.

type Task

type Task = func(context.Context) (retry bool, err error)

Task represents a function to retry. It should return a boolean indicating whether a retry should occur on the given error.

Jump to

Keyboard shortcuts

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