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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user