when retries were exhausted in the retry Run, we were returning nil instead of an error.

This commit is contained in:
Megan Marsh 2019-04-23 13:48:30 -07:00
parent b1ffc1c814
commit e69d95eb37
1 changed files with 3 additions and 1 deletions

View File

@ -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