ExponentialRetry runs the given function until it succeeds or can no longer be retried.
(maxRetries int, waitAfterFailure time.Duration, f func() error)
| 626 | |
| 627 | // ExponentialRetry runs the given function until it succeeds or can no longer be retried. |
| 628 | func ExponentialRetry(maxRetries int, waitAfterFailure time.Duration, |
| 629 | f func() error) error { |
| 630 | var err error |
| 631 | for retry := maxRetries; retry > 0; retry-- { |
| 632 | if err = f(); err == nil { |
| 633 | return nil |
| 634 | } |
| 635 | if waitAfterFailure > 0 { |
| 636 | time.Sleep(waitAfterFailure) |
| 637 | waitAfterFailure *= 2 |
| 638 | } |
| 639 | } |
| 640 | return err |
| 641 | } |
| 642 | |
| 643 | // RetryUntilSuccess runs the given function until it succeeds or can no longer be retried. |
| 644 | func RetryUntilSuccess(maxRetries int, waitAfterFailure time.Duration, |
no outgoing calls
no test coverage detected