blob: ec865b42b358722e5ada640ffaa3ecb0a0b132af [file] [log] [blame]
package exec
import (
"context"
"github.com/cenkalti/backoff/v4"
)
// WithRetryContext enables retries with exponential backoff according to the
// given settings.
func WithRetryContext(ctx context.Context, settings backoff.BackOff) context.Context {
parent := getCtx(ctx)
runFn := func(ctx context.Context, c *Command) error {
run := func() error {
return parent.runFn(ctx, c)
}
return backoff.Retry(run, settings)
}
return NewContext(ctx, runFn)
}