Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Do ¶
Do retries the given function until it succeeds or the retry limit is reached. It takes a context and a function as parameters and optionally accepts additional options. The function is retried based on the specified options, which include the maximum number of retries and the backoff strategy. If the context is canceled, Do returns the context error. If the function returns an error that is not of type RetryableError, Do returns the error. If the retry limit is reached, Do returns ErrRetryLimitReached.
func MarkRetryable ¶
MarkRetryable marks error as retryable by wrapping it in RetryableError.
Types ¶
type Backoff ¶
type Backoff interface { // Next returns the timeout before next retry. Next(retry uint) time.Duration }
Backoff represents backoff logic.
type ConstantBackoff ¶
type ConstantBackoff struct {
// contains filtered or unexported fields
}
ConstantBackoff implements Backoff interface where the backoff is constant.
func NewConstantBackoff ¶
func NewConstantBackoff(minv, maxv, jitter time.Duration) *ConstantBackoff
NewConstantBackoff returns a pointer to a new instance of ConstantBackoff struct, which implements Backoff interface.
type Error ¶
type Error string
Error represents package level errors.
const ( // ErrRetryLimitReached is an error indicating that the retry limit has been reached. ErrRetryLimitReached Error = "retry limit reached" )
type ExponentialBackoff ¶
type ExponentialBackoff struct {
// contains filtered or unexported fields
}
ExponentialBackoff implements Backoff interface where the backoff grows exponentially based on retry count.
func NewExponentialBackoff ¶
func NewExponentialBackoff(f uint, minv, maxv, jitter time.Duration) *ExponentialBackoff
NewExponentialBackoff returns a pointer to a new instance of ExponentialBackoff struct, which implements Backoff interface.
type LinearBackoff ¶
type LinearBackoff struct {
// contains filtered or unexported fields
}
LinearBackoff implements Backoff where the backoff grows linearly based on retry count.
func NewLinearBackoff ¶
func NewLinearBackoff(minv, maxv, jitter time.Duration) *LinearBackoff
NewLinearBackoff returns a pointer to a new instance of ConstantBackoff struct, which implements Backoff interface.
type Option ¶
type Option func(*Options)
Option is a function type that modifies the Options struct.
func WithBackoff ¶
WithBackoff returns an Option function that sets the backoff strategy for retry logic. The Backoff implementation determines the timeout before the next retry based on the number of retries.
func WithLogger ¶
WithLogger specifies the logger to be used for logging within the retry logic.
func WithMaxAttempts ¶
WithMaxAttempts is an Option function that sets the maximum number of attempts for a given operation. It takes a `maxAttempts` parameter of type `uint64` and updates the `maxRetries` field of the Options struct.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options represents the configuration options for retry logic.
func (*Options) Backoff ¶ added in v0.2.8
Backoff returns the current implementation of Backoff interface.
func (*Options) MaxRetries ¶ added in v0.2.8
MaxRetries returns number a max retry attempts.
type RetryableError ¶
type RetryableError struct {
// contains filtered or unexported fields
}
RetryableError represents an error that can be retried. It encapsulates another error type and can be used to distinguish between errors that can be retried from those that cannot.
func (RetryableError) Error ¶
func (e RetryableError) Error() string
func (RetryableError) Unwrap ¶
func (e RetryableError) Unwrap() error
type StaticBackoff ¶
StaticBackoff represents a fixed duration as a backoff strategy.