retries

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: Apache-2.0 Imports: 5 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ManageRetries

func ManageRetries(
	ctx context.Context,
	process string,
	maxAttempts int,
	maxBackoff time.Duration,
	fn func() (bool, error),
) error

ManageRetries executes the provided function until it "succeeds" or the maximum number of attempts has been exhausted. The delay between attempts increases exponentially, but is capped by the value of maxBackoff argument. "Success" requires the provided function to return a bool indicating that no retry should be attempted (false). The indication that a retry should or should not be attempted is SEPARATE from whatever error the provided function may return, with the decision to retry or not being made solely on the basis of the bool value. This makes it possible to retry failures after the provided function has done its own internal error handling. It also makes it possible to circumvent retries in the event that the error encountered is unrecoverable.

Example usage:

var client amqp.Client
err := retries.ManageRetries(ctx, "amqp connect", 10, 10 * time.Second,
	func() (bool, error) {
		var e error
		if client, e = amqp.Dial(address); e != nil {
			return true, errors.Wrap(e, "error dialing AMQP server")
		}
		return false, nil
	},
)
// Handle err

Types

This section is empty.

Jump to

Keyboard shortcuts

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