Documentation ¶
Index ¶
Constants ¶
Stop is used as a signal to indicate that no more retries should be made.
Variables ¶
This section is empty.
Functions ¶
func Retry ¶
Retry the function f until it does not return error or BackOff stops. f is guaranteed to be run at least once. It is the caller's responsibility to reset b after Retry returns.
Retry sleeps the goroutine for the duration returned by BackOff after a failed operation returns.
Types ¶
type Backoff ¶
Backoff is an interface for different types of backoff algorithms.
type ExponentialBackoff ¶
ExponentialBackoff implements the simple exponential backoff described by Douglas Thain at http://dthain.blogspot.de/2009/02/exponential-backoff-in-distributed.html.
func NewExponentialBackoff ¶
func NewExponentialBackoff(initialTimeout, maxTimeout time.Duration) *ExponentialBackoff
NewExponentialBackoff returns a ExponentialBackoff backoff policy. Use initialTimeout to set the first/minimal interval and maxTimeout to set the maximum wait interval.
func (*ExponentialBackoff) Next ¶
func (t *ExponentialBackoff) Next() time.Duration
Next returns the next wait interval.
func (*ExponentialBackoff) Reset ¶
func (t *ExponentialBackoff) Reset()
Reset resets the backoff policy so that it can be reused.
func (*ExponentialBackoff) SendStop ¶
func (b *ExponentialBackoff) SendStop(doStop bool) *ExponentialBackoff
SendStop, when enables, makes Next to return Stop once the maximum timeout is reached.
type Notify ¶
Notify is a notify-on-error function. It receives an operation error and backoff delay if the operation failed (with an error).
NOTE that if the backoff policy stated to stop retrying, the notify function isn't called.
type Operation ¶
type Operation func() error
An Operation is executing by Retry() or RetryNotify(). The operation will be retried using a backoff policy if it returns an error.
type SimpleBackoff ¶
SimpleBackoff takes a list of fixed values for backoff intervals. Each call to Next returns the next value from that fixed list. After each value is returned, subsequent calls to Next will only return the last element. The caller may specify if the values are "jittered".
func NewSimpleBackoff ¶
func NewSimpleBackoff(ticks ...int) *SimpleBackoff
NewSimpleBackoff creates a SimpleBackoff algorithm with the specified list of fixed intervals in milliseconds.
func (*SimpleBackoff) Jitter ¶
func (b *SimpleBackoff) Jitter(doJitter bool) *SimpleBackoff
Jitter, when set, randomizes to return a value of [0.5*value .. 1.5*value].
func (*SimpleBackoff) Next ¶
func (b *SimpleBackoff) Next() time.Duration
Next returns the next wait interval.
func (*SimpleBackoff) SendStop ¶
func (b *SimpleBackoff) SendStop(doStop bool) *SimpleBackoff
SendStop, when enables, makes Next to return Stop once the list of values is exhausted.