package retry
import "github.com/IBM/fp-go/retry"
Index ¶
- Variables
- type RetryPolicy
- func CapDelay(maxDelay time.Duration, policy RetryPolicy) RetryPolicy
- func ConstantDelay(delay time.Duration) RetryPolicy
- func ExponentialBackoff(delay time.Duration) RetryPolicy
- func LimitRetries(i uint) RetryPolicy
- type RetryStatus
Variables ¶
var DefaultRetryStatus = RetryStatus{ IterNumber: 0, CumulativeDelay: 0, PreviousDelay: O.None[time.Duration](), }
DefaultRetryStatus is the default retry status. Exported mostly to allow user code to test their handlers and retry policies.
var Monoid = M.FunctionMonoid[RetryStatus](O.ApplicativeMonoid(M.MakeMonoid( ord.MaxSemigroup(ordDuration).Concat, emptyDuration)))
Monoid '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.
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.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
retry/generic |
- Version
- v1.0.151 (latest)
- Published
- Nov 23, 2024
- Platform
- linux/amd64
- Imports
- 6 packages
- Last checked
- 4 months ago –
Tools for package owners.