waitext

package
v0.54.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package waitext implements behavior similar to https://github.com/cenkalti/backoff on top of k8s.io/apimachinery/pkg/util/wait.

Index

Constants

View Source
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

func DefaultExponentialBackoff() wait.Backoff

DefaultExponentialBackoff creates an exponential backoff with sensible default values. Defaults should match ExponentialBackoff in github.com/cenkalti/backoff.

func NewConstantBackoff

func NewConstantBackoff(interval time.Duration) wait.Backoff

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.

Jump to

Keyboard shortcuts

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