Documentation ¶
Overview ¶
Package waitext implements behavior similar to https://github.com/cenkalti/backoff on top of k8s.io/apimachinery/pkg/util/wait.
Index ¶
Constants ¶
const ( // Forever should be used to simulate infinite retries or backoff increase. // Usually it's wise to have a context with timeout to avoid an infinite loop. Forever = math.MaxInt32 )
Variables ¶
This section is empty.
Functions ¶
func DefaultExponentialBackoff ¶
DefaultExponentialBackoff creates an exponential backoff with sensible default values. Defaults should match ExponentialBackoff in github.com/cenkalti/backoff.
func NewConstantBackoff ¶
NewConstantBackoff creates a backoff that steps at constant intervals. This backoff will run "forever", use WithMaxRetries or a context to put a hard cap. This works similar to ConstantBackOff in github.com/cenkalti/backoff.
func Retry ¶
func Retry(ctx context.Context, backoff wait.Backoff, retries int, operation func(context.Context) (bool, error), retryNotify func(error)) error
Retry executes an operation with retries following these semantics:
The operation is executed at least once (even if context is cancelled)
If operation returns nil error, assumption is that it succeeded
If operation returns non-nil error, then the first boolean return value decides whether to retry or not
The operation will not be retried anymore if
retries reaches 0
the context is cancelled
The end result is:
- nil if operation was successful at least once
- last encountered error from operation if retries are exhausted
- a multi-error if context is cancelled that contains - the ctx.Err(), context.Cause() and last encountered error from the operation
If retryNotify is passed, it is called when making retries. Caveat: this function is similar to wait.ExponentialBackoff but has some important behavior differences like at-least-one execution and retryable errors.
Types ¶
This section is empty.