retry

package
v1.0.36 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRetryStatus = RetryStatus{
	IterNumber:      0,
	CumulativeDelay: 0,
	PreviousDelay:   O.None[time.Duration](),
}

*

  • Initial, default retry status. Exported mostly to allow user code
  • to test their handlers and retry policies.
View Source
var Monoid = M.FunctionMonoid[RetryStatus](O.ApplicativeMonoid(M.MakeMonoid(
	ord.MaxSemigroup(ordDuration).Concat, emptyDuration)))

'RetryPolicy' is a 'Monoid'. You can collapse multiple strategies into one using 'concat'. The semantics of this combination are as follows:

1. If either policy returns 'None', the combined policy returns 'None'. This can be used to inhibit after a number of retries, for example.

2. If both policies return a delay, the larger delay will be used. This is quite natural when combining multiple policies to achieve a certain effect.

Functions

This section is empty.

Types

type RetryPolicy

type RetryPolicy = func(RetryStatus) O.Option[time.Duration]

RetryPolicy is a function that takes an `RetryStatus` and possibly returns a delay in milliseconds. Iteration numbers start at zero and increase by one on each retry. A //None// return value from the function implies we have reached the retry limit.

func CapDelay

func CapDelay(maxDelay time.Duration, policy RetryPolicy) RetryPolicy

CapDelay sets a time-upperbound for any delays that may be directed by the given policy. This function does not terminate the retrying. The policy capDelay(maxDelay, exponentialBackoff(n))` will never stop retrying. It will reach a state where it retries forever with a delay of `maxDelay` between each one. To get termination you need to use one of the 'limitRetries' function variants.

func ConstantDelay

func ConstantDelay(delay time.Duration) RetryPolicy

ConstantDelay delays with unlimited retries

func ExponentialBackoff

func ExponentialBackoff(delay time.Duration) RetryPolicy

ExponentialBackoff grows delay exponentially each iteration. Each delay will increase by a factor of two.

func LimitRetries

func LimitRetries(i uint) RetryPolicy

LimitRetries retries immediately, but only up to `i` times.

type RetryStatus

type RetryStatus struct {
	// Iteration number, where `0` is the first try
	IterNumber uint
	// Delay incurred so far from retries
	CumulativeDelay time.Duration
	// Latest attempt's delay. Will always be `none` on first run.
	PreviousDelay O.Option[time.Duration]
}

func ApplyPolicy

func ApplyPolicy(policy RetryPolicy, status RetryStatus) RetryStatus

*

  • Apply policy on status to see what the decision would be.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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