retry

package
v2.3.6+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2020 License: MIT Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDo = NewDo(30 * time.Second)

DefaultDo is the default executor for retrying operations.

Functions

func Action

func Action(description string, timeout time.Duration, action ActionFunc) error

Action performs the specified action until it succeeds or times out.

description is a short description of the function used for logging. timeout is the period of time before the process action is the action function to invoke

Returns the error (if any) passed to Context.Fail or caused by the operation timing out.

func IsTimeoutError

func IsTimeoutError(err error) bool

IsTimeoutError determines whether the specified error represents an operation timeout.

Types

type ActionFunc

type ActionFunc func(context Context)

ActionFunc is a function representing a retryable operation that does not directly return any value.

Feel free to publish values from the function to variables in the enclosing scope.

type Context

type Context interface {
	// Retry the operation once the current iteration completes.
	Retry()

	// Mark the current iteration as failed due to the specified error.
	Fail(err error)
}

Context represents contextual information about the current iteration of a retryable operation.

type Do

type Do interface {
	// GetRetryPeriod retrieves the Do's currently-configured retry period.
	//
	// This determines the *maximum* period that the Do will wait between retries.
	GetRetryPeriod() time.Duration

	// SetRetryPeriod configures the Do's retry period.
	//
	// This determines the *maximum* period that the Do will wait between retries.
	SetRetryPeriod(retryPeriod time.Duration)

	// DoAction performs the specified action until it succeeds or times out.
	//
	// description is a short description of the function used for logging.
	// timeout is the period of time before the process
	// action is the action function to invoke
	//
	// Returns the error (if any) passed to Context.Fail or caused by the operation timing out.
	Action(description string, timeout time.Duration, action ActionFunc) error
}

Do is used to execute retriable operations.

func NewDo

func NewDo(retryPeriod time.Duration) Do

NewDo creates a new Do.

type OperationTimeoutError

type OperationTimeoutError struct {
	// The operation description.
	OperationDescription string

	// The operation timeout period.
	Timeout time.Duration

	// The number of attempts that were made to perform the operation.
	Attempts int
}

OperationTimeoutError is raised when the timeout for an operation is exceeded.

func (*OperationTimeoutError) Error

func (timeoutError *OperationTimeoutError) Error() string

Error creates a string representation of the OperationTimeoutError.

Jump to

Keyboard shortcuts

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