...

Package task

Overview ▾

type Retryable

Retryable represents a task that can be retried.

type Retryable struct {
    // contains filtered or unexported fields
}

func NewRetryable

func NewRetryable(description string, runner Runner) Retryable

NewRetryable creates and returns a new Retryable task.

func (Retryable) RetryWithSchedule

func (r Retryable) RetryWithSchedule(schedule []time.Duration, errorIfTimeout bool) (interface{}, error)

RetryWithSchedule invokes the retryable runner function, and keeps retrying until this runner returns an exitCondition that evaluates to false, or the given timeout expires. The timeout schedule can be a seen as a backoff schedule, in the sense that before recalling the runner function, RetryWithSchedule waits for each duration defined in the given schedule. If the exitCondition is not true after all retries, the behavior is governed by the errorIfTimeout parameter. If errorIfTimeout is true, then an error is returned.

type Runner

Runner is a function that will get invoked via RetryWithSchedule. If exitCondition is false, the function will get invoked again, until the given timeout schedule expires. It then returns a result of any type along with a potential error.

type Runner func() (exitCondition bool, result interface{}, err error)