Documentation
¶
Index ¶
- func IsRetryableError(err error) bool
- func NewDeadlineError(deadline time.Duration, lastErr error) error
- func NewMaxRetryError(maxAttempts int, lastErr error) error
- func NewRetryableError(err error) error
- type Backoff
- type DeadlineRetryError
- type Group
- type MaxRetryExceedError
- type RetryableError
- type TaskFunc
- func NewTaskFunc(fn TaskFunc, decorators ...TaskFuncDecorator) TaskFunc
- func Retry(retryInterval time.Duration, retryFunc TaskFunc) TaskFunc
- func RetryUntil(maxAttempts int, retryInterval time.Duration, retryFunc TaskFunc) TaskFunc
- func RetryWithBackoff(maxAttempts int, backoff Backoff, retryFunc TaskFunc) TaskFunc
- func RetryWithDeadline(timeoutDeadline time.Duration, retryInterval time.Duration, retryFunc TaskFunc) TaskFunc
- func Task(t TaskInterface) TaskFunc
- type TaskFuncDecorator
- type TaskInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsRetryableError ¶
IsRetryableError checks if the error is retryable.
func NewDeadlineError ¶
NewDeadlineRetryError creates DeadlineRetryError instance.
func NewMaxRetryError ¶
NewMaxRetryError creates MaxRetryError instance.
func NewRetryableError ¶
NewRetryableError wraps an error and makes it retryable.
Types ¶
type DeadlineRetryError ¶
type DeadlineRetryError struct {
// contains filtered or unexported fields
}
DeadlineRetryError is returned when RetryWithDeadline could not complete successfully within given deadline.
func (*DeadlineRetryError) Cause ¶
func (err *DeadlineRetryError) Cause() error
Cause returns the last error before the deadline is exceeded.
func (*DeadlineRetryError) Error ¶
func (err *DeadlineRetryError) Error() string
Error returns the error message.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is used to wait for a group of tasks to finish.
It will stop all the tasks on the first task failure, and the Wait() method will return only the first encountered error.
type MaxRetryExceedError ¶
type MaxRetryExceedError struct {
// contains filtered or unexported fields
}
MaxRetryExceedError is returned when RetryUntil could not complete successfully for a given maxAttempts retries.
func (*MaxRetryExceedError) Cause ¶
func (err *MaxRetryExceedError) Cause() error
Cause returns the last error before the max retry attempts is exceeded.
func (*MaxRetryExceedError) Error ¶
func (err *MaxRetryExceedError) Error() string
Error returns the error message.
type RetryableError ¶
RetryableError error signify that the task can be retried.
type TaskFunc ¶
TaskFunc specify the functions that are run by the task group.
func NewTaskFunc ¶
func NewTaskFunc(fn TaskFunc, decorators ...TaskFuncDecorator) TaskFunc
NewTaskFunc creates a TaskFunc decorated with the provided decorators.
func Retry ¶
Retry retries a task until it returns no error or the returned error is non retriable. An error is retriable when it implements the RetryableError interface and its IsRetryable method returns true. The retryInterval specify how much time to wait between every retry.
func RetryUntil ¶
RetryUntil retries a task maxAttempts times until it returns no error or the returned error is non retriable. An error is retriable when it implements the RetryableError interface and its IsRetryable method returns true. The retryInterval specify how much time to wait between every retry. If the task do not complete for maxAttempts retries, RetryUntil will return MaxRetryExceedError.
NOTE: when the cancel channel is closed, RetryUntil will not return an error, even if the retryFunc had failed couple of times so far.
func RetryWithBackoff ¶
RetryWithBackoff retries a task maxAttempts times with exponential backoff until it returns no error or the returned error is non retriable.
An error is retriable when it implements the RetryableError interface and its IsRetryable method returns true.
If the task do not complete for maxAttempts retries, RetryWithBackoff will return MaxRetryExceedError.
NOTE: when the cancel channel is closed, RetryWithBackoff will not return an error, even if the retryFunc had failed couple of times so far.
If maxAttempts is -1, it will retry infinitely.
func RetryWithDeadline ¶
func RetryWithDeadline( timeoutDeadline time.Duration, retryInterval time.Duration, retryFunc TaskFunc, ) TaskFunc
RetryWithDeadline retries a task until it returns no error, or the returned error is non retriable, or timeoutDeadline is exceeded. An error is retriable when it implements the RetryableError interface and its IsRetryable method returns true. The retryInterval specify how much time to wait between every retry. If the task do not complete and timeoutDeadline is exceeded, RetryWithDeadline will return DeadlineRetryError.
NOTE: when the cancel channel is closed, RetryWithDeadline will not return an error, even if the retryFunc had failed couple of times so far.
func Task ¶
func Task(t TaskInterface) TaskFunc
Task adapts a TaskInterface to TaskFunc required by the task.Group to run tasks.