retry

package
v0.0.0-...-c46dd35 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package retry provides a generic retry mechanism with exponential backoff. It is designed for operations that may fail transiently, such as gRPC calls or network requests, where retrying after a short delay can succeed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, cfg Config, fn func(ctx context.Context) error) error

Do executes fn, retrying on errors that IsRetryable returns true for. It uses exponential backoff between retries and respects context cancellation.

func GRPCTransient

func GRPCTransient(err error) bool

GRPCTransient returns true for gRPC errors that indicate a transient failure: Unavailable and DeadlineExceeded.

Types

type Config

type Config struct {
	// MaxAttempts is the total number of attempts including the initial call.
	MaxAttempts int
	// BaseBackoff is the initial backoff duration. Each subsequent retry doubles it.
	BaseBackoff time.Duration
	// IsRetryable determines whether an error should be retried.
	IsRetryable func(error) bool
}

Config holds the retry parameters.

Jump to

Keyboard shortcuts

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