Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 1.18 KB

readme.md

File metadata and controls

53 lines (41 loc) · 1.18 KB

Retry codecov

Retry with context or not.

Default using exponential backoff.

Example

func DoSomething() error {
	err := retry.Do( // use DoWithContext() if you need context
		doSomeThing(),
		retry.CheckRetryable(checkRetryable),
		retry.MaxRetryTimes(uint(5)),
		retry.Interval(100.0*time.Millisecond),
		retry.MaxInterval(5000.0*time.Millisecond),
		retry.MaxJitterInterval(10.0*time.Millisecond),
		retry.MaxElapsedTime(10*time.Minute),
		retry.Multiplier(1.5),
	)
	return err
}

func doSomething() error {
    return retryableErr
}

func checkRetryable(err error) bool {
    if err == retryableErr {
        return true
    }
    return false
}

Default parameters

DefaultMaxRetryTimes  = 10
DefaultInterval       = 100.0 * time.Millisecond
DefaultMaxInterval    = 1000.0 * time.Millisecond
DefaultJitterInterval = 30.0 * time.Millisecond
DefaultMultiplier     = 2.0
DefaultMaxElapsedTime = 5 * time.Minute

Reference

backoff

retry-go

retry