Documentation ¶
Index ¶
Constants ¶
const DefaultTimeout = 5 * time.Minute
DefaultTimeout is our opinionated default timeout for retrying database and Redis operations.
Variables ¶
This section is empty.
Functions ¶
func ResetTimeout ¶ added in v1.2.0
ResetTimeout changes the possibly expired timer t to expire after duration d.
If the timer has already expired and nothing has been received from its channel, it is automatically drained as if the timer had never expired.
func Retryable ¶
Retryable returns true for common errors that are considered retryable, i.e. temporary, timeout, DNS, connection refused and reset, host down and unreachable and network down and unreachable errors. In addition, any database error is considered retryable.
func WithBackoff ¶
func WithBackoff( ctx context.Context, retryableFunc RetryableFunc, retryable IsRetryable, b backoff.Backoff, settings Settings, ) (err error)
WithBackoff retries the passed function if it fails and the error allows it to retry. The specified backoff policy is used to determine how long to sleep between attempts.
Types ¶
type IsRetryable ¶
IsRetryable checks whether a new attempt can be started based on the error passed.
type RetryableFunc ¶
RetryableFunc is a retryable function.
type Settings ¶
type Settings struct { // If >0, Timeout lets WithBackoff stop retrying gracefully once elapsed based on the following criteria: // * If the execution of RetryableFunc has taken longer than Timeout, no further attempts are made. // * If Timeout elapses during the sleep phase between retries, one final retry is attempted. // * RetryableFunc is always granted its full execution time and is not canceled if it exceeds Timeout. // This means that WithBackoff may not stop exactly after Timeout expires, // or may not retry at all if the first execution of RetryableFunc already takes longer than Timeout. Timeout time.Duration // OnRetryableError is called if a retryable error occurs. OnRetryableError func(elapsed time.Duration, attempt uint64, err, lastErr error) // OnSuccess is called once the operation succeeds. OnSuccess func(elapsed time.Duration, attempt uint64, lastErr error) }
Settings aggregates optional settings for WithBackoff.