Fix option names and functions to make lint happy.
Fixes: https://github.com/containers/common/issues/1058 [NO NEW TESTS NEEDED] Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
ac816884f5
commit
20043edfcc
|
|
@ -139,7 +139,7 @@ type CopyOptions struct {
|
|||
// copier is an internal helper to conveniently copy images.
|
||||
type copier struct {
|
||||
imageCopyOptions copy.Options
|
||||
retryOptions retry.RetryOptions
|
||||
retryOptions retry.Options
|
||||
systemContext *types.SystemContext
|
||||
policyContext *signature.PolicyContext
|
||||
|
||||
|
|
@ -370,7 +370,7 @@ func (c *copier) copy(ctx context.Context, source, destination types.ImageRefere
|
|||
}
|
||||
return err
|
||||
}
|
||||
return returnManifest, retry.RetryIfNecessary(ctx, f, &c.retryOptions)
|
||||
return returnManifest, retry.IfNecessary(ctx, f, &c.retryOptions)
|
||||
}
|
||||
|
||||
// checkRegistrySourcesAllows checks the $BUILD_REGISTRY_SOURCES environment
|
||||
|
|
|
|||
|
|
@ -16,26 +16,29 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RetryOptions defines the option to retry
|
||||
// revive does not like the name because the package is already called retry
|
||||
//nolint:revive
|
||||
type RetryOptions struct {
|
||||
MaxRetry int // The number of times to possibly retry
|
||||
Delay time.Duration // The delay to use between retries, if set
|
||||
// Options defines the option to retry.
|
||||
type Options struct {
|
||||
MaxRetry int // The number of times to possibly retry.
|
||||
Delay time.Duration // The delay to use between retries, if set.
|
||||
}
|
||||
|
||||
// RetryIfNecessary retries the operation in exponential backoff with the retryOptions
|
||||
//
|
||||
// revive does not like the name because the package is already called retry
|
||||
//nolint:revive
|
||||
func RetryIfNecessary(ctx context.Context, operation func() error, retryOptions *RetryOptions) error {
|
||||
// RetryOptions is deprecated, use Options.
|
||||
type RetryOptions = Options // nolint:revive
|
||||
|
||||
// RetryIfNecessary deprecated function use IfNecessary.
|
||||
func RetryIfNecessary(ctx context.Context, operation func() error, options *Options) error { // nolint:revive
|
||||
return IfNecessary(ctx, operation, options)
|
||||
}
|
||||
|
||||
// IfNecessary retries the operation in exponential backoff with the retry Options.
|
||||
func IfNecessary(ctx context.Context, operation func() error, options *Options) error {
|
||||
err := operation()
|
||||
for attempt := 0; err != nil && isRetryable(err) && attempt < retryOptions.MaxRetry; attempt++ {
|
||||
for attempt := 0; err != nil && isRetryable(err) && attempt < options.MaxRetry; attempt++ {
|
||||
delay := time.Duration(int(math.Pow(2, float64(attempt)))) * time.Second
|
||||
if retryOptions.Delay != 0 {
|
||||
delay = retryOptions.Delay
|
||||
if options.Delay != 0 {
|
||||
delay = options.Delay
|
||||
}
|
||||
logrus.Warnf("Failed, retrying in %s ... (%d/%d). Error: %v", delay, attempt+1, retryOptions.MaxRetry, err)
|
||||
logrus.Warnf("Failed, retrying in %s ... (%d/%d). Error: %v", delay, attempt+1, options.MaxRetry, err)
|
||||
select {
|
||||
case <-time.After(delay):
|
||||
break
|
||||
|
|
|
|||
Loading…
Reference in New Issue