retry

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package retry provides retry policies for activities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder provides a fluent API for building policies.

func NewBuilder

func NewBuilder() *Builder

NewBuilder creates a new policy builder.

func (*Builder) Build

func (b *Builder) Build() *Policy

Build returns the configured policy.

func (*Builder) WithInitialInterval

func (b *Builder) WithInitialInterval(d time.Duration) *Builder

WithInitialInterval sets the initial retry interval.

func (*Builder) WithJitter

func (b *Builder) WithJitter(factor float64) *Builder

WithJitter sets the randomization factor.

func (*Builder) WithMaxAttempts

func (b *Builder) WithMaxAttempts(n int) *Builder

WithMaxAttempts sets the maximum number of attempts.

func (*Builder) WithMaxInterval

func (b *Builder) WithMaxInterval(d time.Duration) *Builder

WithMaxInterval sets the maximum retry interval.

func (*Builder) WithMultiplier

func (b *Builder) WithMultiplier(m float64) *Builder

WithMultiplier sets the backoff multiplier.

func (*Builder) WithNonRetryableErrors

func (b *Builder) WithNonRetryableErrors(errs ...error) *Builder

WithNonRetryableErrors sets errors that should not trigger retries.

type Policy

type Policy struct {
	// MaxAttempts is the maximum number of attempts (including the first).
	// 0 means no limit.
	MaxAttempts int

	// InitialInterval is the delay before the first retry.
	InitialInterval time.Duration

	// MaxInterval is the maximum delay between retries.
	MaxInterval time.Duration

	// Multiplier is the factor by which the interval increases.
	Multiplier float64

	// RandomizationFactor adds jitter to the delay.
	// A value of 0.5 means the actual delay will be within [delay * 0.5, delay * 1.5].
	RandomizationFactor float64

	// NonRetryableErrors is a list of errors that should not be retried.
	// Errors are matched using errors.Is.
	NonRetryableErrors []error
}

Policy defines the retry behavior for activities.

func DefaultPolicy

func DefaultPolicy() *Policy

DefaultPolicy returns a sensible default retry policy.

func Exponential

func Exponential(maxAttempts int, initial, maxInterval time.Duration, multiplier float64) *Policy

Exponential returns an exponential backoff policy.

func Fixed

func Fixed(maxAttempts int, interval time.Duration) *Policy

Fixed returns a policy with fixed delay between retries.

func NoRetry

func NoRetry() *Policy

NoRetry returns a policy that never retries.

func (*Policy) GetDelay

func (p *Policy) GetDelay(attempts int) time.Duration

GetDelay calculates the delay before the next retry.

func (*Policy) ShouldRetry

func (p *Policy) ShouldRetry(attempts int, err error) bool

ShouldRetry returns true if the operation should be retried.

Jump to

Keyboard shortcuts

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