-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package utils | ||
|
||
import ( | ||
"github.com/cenkalti/backoff/v3" | ||
"log" | ||
"time" | ||
) | ||
|
||
// WithRetry retries a given function with an exponential backoff until maxTime is reached | ||
func WithRetry(do func() error, interval, maxInterval, maxTime time.Duration) error { | ||
exponential := backoff.NewExponentialBackOff() | ||
exponential.MaxElapsedTime = maxTime | ||
exponential.InitialInterval = interval | ||
exponential.MaxInterval = maxInterval | ||
|
||
err := backoff.RetryNotify(do, exponential, func(err error, d time.Duration) { | ||
log.Printf("call failed, retrying in %d. Error: %v", d.Round(time.Second), err) | ||
}) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters