build: upgrade to go 1.17 and dependencies

This commit is contained in:
2021-09-01 22:13:52 +02:00
parent 0fe45a3c9c
commit fdedd70471
120 changed files with 10274 additions and 1888 deletions

View File

@ -43,8 +43,14 @@ SEE ALSO
* [matryer/try](https://github.com/matryer/try) - very popular package, nonintuitive interface (for me)
BREAKING CHANGES
3.0.0
* `DelayTypeFunc` accepts a new parameter `err` - this breaking change affects only your custom Delay Functions. This change allow [make delay functions based on error](examples/delay_based_on_error_test.go).
1.0.2 -> 2.0.0
* argument of `retry.Delay` is final delay (no multiplication by `retry.Units` anymore)
@ -65,6 +71,7 @@ BREAKING CHANGES
package retry
import (
"context"
"fmt"
"strings"
"time"
@ -81,6 +88,7 @@ var (
DefaultRetryIf = IsRecoverable
DefaultDelayType = CombineDelay(BackOffDelay, RandomDelay)
DefaultLastErrorOnly = false
DefaultContext = context.Background()
)
func Do(retryableFunc RetryableFunc, opts ...Option) error {
@ -95,6 +103,7 @@ func Do(retryableFunc RetryableFunc, opts ...Option) error {
retryIf: DefaultRetryIf,
delayType: DefaultDelayType,
lastErrorOnly: DefaultLastErrorOnly,
context: DefaultContext,
}
//apply opts
@ -102,6 +111,10 @@ func Do(retryableFunc RetryableFunc, opts ...Option) error {
opt(config)
}
if err := config.context.Err(); err != nil {
return err
}
var errorLog Error
if !config.lastErrorOnly {
errorLog = make(Error, config.attempts)
@ -127,11 +140,17 @@ func Do(retryableFunc RetryableFunc, opts ...Option) error {
break
}
delayTime := config.delayType(n, config)
delayTime := config.delayType(n, err, config)
if config.maxDelay > 0 && delayTime > config.maxDelay {
delayTime = config.maxDelay
}
time.Sleep(delayTime)
select {
case <-time.After(delayTime):
case <-config.context.Done():
return config.context.Err()
}
} else {
return nil
}