retry

package
v0.0.0-...-c124da1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package retry provides configurable retry policies with backoff strategies for gofly service calls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, p Policy, fn func() error) error

Do executes fn and retries according to p until success, context cancellation, or the policy budget is exhausted.

Types

type BackoffFunc

type BackoffFunc func(attempt int) time.Duration

BackoffFunc computes the delay before a given retry attempt.

func ExponentialBackoff

func ExponentialBackoff(base, max time.Duration) BackoffFunc

ExponentialBackoff returns a BackoffFunc that doubles the delay on each attempt, capped at max.

func FixedBackoff

func FixedBackoff(d time.Duration) BackoffFunc

FixedBackoff returns a BackoffFunc that always returns d.

func JitterBackoff

func JitterBackoff(next BackoffFunc, ratio float64) BackoffFunc

JitterBackoff wraps a BackoffFunc and adds random jitter within ±ratio of the computed delay, smoothing thundering-herd retries.

type Budget

type Budget interface {
	AllowRetry(retry int, err error) bool
}

Budget decides whether a retry is permitted.

type MaxRetriesBudget

type MaxRetriesBudget struct {
	MaxRetries int
}

MaxRetriesBudget allows retries up to a fixed maximum.

func (MaxRetriesBudget) AllowRetry

func (b MaxRetriesBudget) AllowRetry(retry int, err error) bool

AllowRetry reports whether retry is within the configured maximum.

type Policy

type Policy struct {
	Attempts    int
	Backoff     time.Duration
	BackoffFunc BackoffFunc
	Budget      Budget
	ShouldRetry func(error) bool
}

Policy defines retry behaviour: number of attempts, backoff, budget and per-error retry eligibility.

Jump to

Keyboard shortcuts

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