1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 23:22:28 +08:00

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
2024-02-22 03:39:45 +01:00
committed by GitHub
parent 66fd8cf651
commit d367397dab
3 changed files with 234 additions and 2 deletions

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