retry

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnError

func OnError(
	ctx context.Context,
	retryLimit int,
	retryDelay time.Duration,
	retryResetTimeout time.Duration,
	workName string,
	workFn RetryFunc,
) error

OnError continuously invokes the provided work function (workFn) until either the context (ctx) is canceled or the error channel returned by workFn is closed. If workFn encounters an error, OnError will retry invoking workFn based on the provided retry parameters.

Parameters:

  • ctx: the context to monitor for cancellation. If canceled, OnError will exit without error.
  • retryLimit: the maximum number of retries for workFn upon encountering an error.
  • retryDelay: the duration to wait before retrying workFn after an error.
  • retryResetCount: Specifies the duration of continuous error-free operation required before the retry count is reset. If the work function operates without errors for this duration, any subsequent error will restart the retry count from the beginning.
  • workName: a name or descriptor for the work function, used for logging purposes.
  • workFn: a function that performs some work and returns an error channel. This channel emits errors encountered during the work.

Returns: - If the context is canceled, the function returns nil. - If the error channel is closed, a warning is logged, and the function returns nil. - If the retry limit is reached, the function returns the error from the channel.

Note: After each error, a delay specified by retryDelay is introduced before retrying workFn.func OnError(

Types

type RetryFunc

type RetryFunc func() chan error

Jump to

Keyboard shortcuts

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