retry

package
v0.0.0-...-4dcfcdd Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package retry contains utility code for retrying database transactions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute[P types.AnyPool](ctx context.Context, db P, query string, args ...any) error

Execute is a wrapper around Retry that can be used for sql queries that don't have any return values.

func Loop

func Loop(
	ctx context.Context, info HasInfo, fn func(ctx context.Context, sideEffect *Marker) error,
) error

Loop is a convenience wrapper to automatically retry idempotent database operations that experience a transaction or a connection failure. The provided callback may indicate that it has started generating observable effects (e.g. sending result data) by calling its second parameter to disable the retry behavior.

If Loop is called in a reentrant fashion, the retry behavior will be suppressed within an inner loop, allowing the retryable error to percolate into the outer loop.

func Retry

func Retry(ctx context.Context, info HasInfo, idempotent func(context.Context) error) error

Retry is a convenience wrapper to automatically retry idempotent database operations that experience a transaction or a connection failure. The provided callback must be entirely idempotent, with no observable side-effects during its execution.

Types

type HasInfo

type HasInfo interface {
	Info() *types.PoolInfo
}

HasInfo contains the Info method.

type Marker

type Marker bool

Marker is a settable flag.

func (*Marker) Mark

func (m *Marker) Mark()

Mark sets the flag.

func (*Marker) Marked

func (m *Marker) Marked() bool

Marked returns the flag status.

Jump to

Keyboard shortcuts

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