Add exponential With jitter backoff (#174)

* Add exponential With jitter backoff

Adds exponential + jitter retry policy. To enable drastic slow down of sending out requests to any external system.

Jitter in computational contexts refers to the addition of a small random variation to a value
to break the symmetric patterns

* Retry with exp: Allow shift for all multiple of 2
This commit is contained in:
donutloop authored and GitHub committed 2024-02-22 10:39:45 +08:00
1 parent 66fd8cf651
commit d367397dab
3 files changed
+234 -2

No files matched your search

+21
View File
@@ -51,6 +51,27 @@ func ExampleRetryWithLinearBackoff() {
// 3
}
func ExampleRetryWithExponentialWithJitterBackoff() {
number := 0
increaseNumber := func() error {
number++
if number == 3 {
return nil
}
return errors.New("error occurs")
}
err := Retry(increaseNumber, RetryWithExponentialWithJitterBackoff(time.Microsecond*50, 2, time.Microsecond*25))
if err != nil {
return
}
fmt.Println(number)
// Output:
// 3
}
func ExampleRetryTimes() {
number := 0