serviceutil

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const MaxAttemptsBeforeResetDefault = 7

MaxAttemptsBeforeResetDefault is the number of attempts during exponential backoff after which attempts is reset so that sleep durations aren't flung into a ridiculously distant future. This constant is typically injected into the CancellableSleepExponentialBackoff function. It could technically take another value instead, but shouldn't unless there's a good reason to do so.

The value of 7 corresponds to a max sleep duration of 64 seconds ±10% jitter.

Variables

This section is empty.

Functions

func CancellableSleep

func CancellableSleep(ctx context.Context, sleepDuration time.Duration)

CancellableSleep sleeps for the given duration, but returns early if context has been cancelled.

func CancellableSleepC

func CancellableSleepC(ctx context.Context, sleepDuration time.Duration) <-chan struct{}

CancellableSleepC sleeps for the given duration, but returns early if context has been cancelled.

This variant returns a channel that should be waited on and which will be closed when either the sleep or context is done.

func ExponentialBackoff

func ExponentialBackoff(attempt, maxAttemptsBeforeReset int) time.Duration

ExponentialBackoff returns a duration for a reasonable exponential backoff interval for a service based on the given attempt number, which can then be fed into CancellableSleep to perform the sleep. Uses a 2**N second algorithm, +/- 10% random jitter. Sleep is cancelled if the given context is cancelled.

Attempt should start at one for the first backoff/failure.

Backoff values when using MaxAttemptsBeforeResetDefault are: - 1s - 2s - 4s - 8s - 16s - 32s - 64s.

Types

This section is empty.

Jump to

Keyboard shortcuts

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