Documentation ¶
Overview ¶
retry is used to keep trying something until it works.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Operation ¶
type Operation func() error
Operation is passed to Do() and is the code you would like to retry.
type Status ¶
type Status struct { // Retried is the number of retries done (which can be 0 if the Operation // only needed to be run once). Retried int // StoppedBecause is the Reason retries were stopped. StoppedBecause Reason // Err is the last return value of the Operation. Err error }
Status is returned by Do() to explain what happened when retrying your Operation. It can be stringified or used as an error that wraps Err.
func Do ¶
func Do(ctx context.Context, op Operation, until Until, bo *backoff.Backoff, activity string) *Status
Do will run op at least once, and then will keep retrying it unless the until returns a Reason to stop, or the context has been cancelled. The amount of time between retries is determined by bo.
The context is also used to end bo's sleep early, if cancelled during a sleep.
If any retries were required, the returned Status is logged using the global context logger at debug level. Any Backoff sleeps will have been logged sharing a unique retryset id, and a retrynum. All logs will include the given activity.
Note that bo is NOT Reset() during this function.
type Until ¶
type Until interface { // ShouldStop takes the number of retries so far along with the error from // the last attempt, and returns a non-blank Reason if no more attempts // should be made. ShouldStop(retries int, err error) Reason }
Until is used by Retry to determine when to stop retrying.
type UntilLimit ¶
type UntilLimit struct {
Max int
}
UntilLimit implements Until, stopping retries after Max retries. A Max of 0 means "don't retry". A Max of 1 means up to 1 retry will be attempted, and so on.
func (*UntilLimit) ShouldStop ¶
func (u *UntilLimit) ShouldStop(retries int, err error) Reason
ShouldStop returns BecauseLimitReached when retries is greater than or equal to Max. err is not considered.
type UntilNoError ¶
type UntilNoError struct{}
UntilNoError implements Until, stopping retries when the error passed to ShouldStop is nil.
func (*UntilNoError) ShouldStop ¶
func (u *UntilNoError) ShouldStop(retries int, err error) Reason
ShouldStop returns BecauseErrorNil when err is nil. retries is not considered.