retry

package
v0.0.0-...-640d511 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RetryWithBackoff

func RetryWithBackoff[T any](ctx context.Context, cfg RetryConfig, operation string, isRetryable func(error) bool, fn func() (T, error)) (T, error)

RetryWithBackoff executes the given function with exponential backoff retry. It only retries on errors that are classified as retryable by the provided isRetryable function.

Types

type RetryConfig

type RetryConfig struct {
	// MaxRetries is the maximum number of retry attempts (default: 5)
	// 0 means do not retry at all.
	MaxRetries int
	// BaseBackoff is the initial backoff duration (default: 1s, higher than typical due to quota nature)
	BaseBackoff time.Duration
	// MaxBackoff is the maximum backoff duration (default: 60s)
	MaxBackoff time.Duration
	// MaxJitter is the maximum random jitter added to backoff (default: 500ms)
	MaxJitter time.Duration
}

RetryConfig configures retry behavior for API calls. This is particularly useful for handling rate limit and transient server errors.

func DefaultRetryConfig

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns a retry configuration suitable for quota and rate limit errors. Uses longer backoffs than typical retry configs because quota-based rate limits often require more time to recover.

func (RetryConfig) Validate

func (c RetryConfig) Validate() error

Validate checks that the retry configuration has valid values.

Jump to

Keyboard shortcuts

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