when retries were exhausted in the retry Run, we were returning nil instead of an error.
This commit is contained in:
parent
b1ffc1c814
commit
e69d95eb37
|
@ -25,6 +25,8 @@ type Config struct {
|
||||||
ShouldRetry func(error) bool
|
ShouldRetry func(error) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var RetryExhaustedError error = fmt.Errorf("Function never succeeded in Retry")
|
||||||
|
|
||||||
// Run fn until context is cancelled up until StartTimeout time has passed.
|
// Run fn until context is cancelled up until StartTimeout time has passed.
|
||||||
func (cfg Config) Run(ctx context.Context, fn func(context.Context) error) error {
|
func (cfg Config) Run(ctx context.Context, fn func(context.Context) error) error {
|
||||||
retryDelay := func() time.Duration { return 2 * time.Second }
|
retryDelay := func() time.Duration { return 2 * time.Second }
|
||||||
|
@ -43,7 +45,7 @@ func (cfg Config) Run(ctx context.Context, fn func(context.Context) error) error
|
||||||
for try := 0; ; try++ {
|
for try := 0; ; try++ {
|
||||||
var err error
|
var err error
|
||||||
if cfg.Tries != 0 && try == cfg.Tries {
|
if cfg.Tries != 0 && try == cfg.Tries {
|
||||||
return err
|
return RetryExhaustedError
|
||||||
}
|
}
|
||||||
if err = fn(ctx); err == nil {
|
if err = fn(ctx); err == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue