retry

package
v0.0.0-...-35dcf12 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRetriable

func IsRetriable(err error) bool

IsRetriable determines if an error is retriable. Returns true for transient errors that may succeed on retry.

func Wrap

func Wrap(db types.DBTX, config Config) types.DBTX

Wrap wraps a DBTX with retry logic using the provided options.

Types

type Config

type Config struct {
	// MaxAttempts is the maximum number of attempts before giving up.
	MaxAttempts int
	// InitialBackoff is the initial backoff duration before the first retry.
	InitialBackoff time.Duration
	// MaxBackoff is the maximum backoff duration between retries.
	MaxBackoff time.Duration
	// BackoffMultiplier is the factor by which backoff increases each attempt.
	BackoffMultiplier float64
}

Config holds the configuration for retry behavior.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default retry configuration.

func (*Config) Apply

func (c *Config) Apply(opts ...Option)

Apply applies all options to the config.

type Option

type Option func(*Config)

Option is a functional option for configuring retry behavior.

func WithBackoffMultiplier

func WithBackoffMultiplier(m float64) Option

WithBackoffMultiplier sets the backoff multiplier.

func WithInitialBackoff

func WithInitialBackoff(d time.Duration) Option

WithInitialBackoff sets the initial backoff duration.

func WithMaxAttempts

func WithMaxAttempts(n int) Option

WithMaxAttempts sets the maximum number of retry attempts.

func WithMaxBackoff

func WithMaxBackoff(d time.Duration) Option

WithMaxBackoff sets the maximum backoff duration.

type RetryableDBTX

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

RetryableDBTX wraps a DBTX with retry logic.

func (*RetryableDBTX) Exec

func (r *RetryableDBTX) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)

Exec executes a query with retry logic.

func (*RetryableDBTX) Query

func (r *RetryableDBTX) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)

Query executes a query that returns rows with retry logic. The caller is responsible for closing the returned rows.

func (*RetryableDBTX) QueryRow

func (r *RetryableDBTX) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row

QueryRow executes a query that returns a single row with retry logic. Since pgx.Row doesn't expose errors until Scan(), we wrap it in a retryableRow.

Jump to

Keyboard shortcuts

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