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.
|
// copier is an internal helper to conveniently copy images.
|
||||||
type copier struct {
|
type copier struct {
|
||||||
imageCopyOptions copy.Options
|
imageCopyOptions copy.Options
|
||||||
retryOptions retry.RetryOptions
|
retryOptions retry.Options
|
||||||
systemContext *types.SystemContext
|
systemContext *types.SystemContext
|
||||||
policyContext *signature.PolicyContext
|
policyContext *signature.PolicyContext
|
||||||
|
|
||||||
|
|
@ -370,7 +370,7 @@ func (c *copier) copy(ctx context.Context, source, destination types.ImageRefere
|
||||||
}
|
}
|
||||||
return err
|
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
|
// checkRegistrySourcesAllows checks the $BUILD_REGISTRY_SOURCES environment
|
||||||
|
|
|
||||||
|
|
@ -16,26 +16,29 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RetryOptions defines the option to retry
|
// Options defines the option to retry.
|
||||||
// revive does not like the name because the package is already called retry
|
type Options struct {
|
||||||
//nolint:revive
|
MaxRetry int // The number of times to possibly retry.
|
||||||
type RetryOptions struct {
|
Delay time.Duration // The delay to use between retries, if set.
|
||||||
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
|
// RetryOptions is deprecated, use Options.
|
||||||
//
|
type RetryOptions = Options // nolint:revive
|
||||||
// revive does not like the name because the package is already called retry
|
|
||||||
//nolint:revive
|
// RetryIfNecessary deprecated function use IfNecessary.
|
||||||
func RetryIfNecessary(ctx context.Context, operation func() error, retryOptions *RetryOptions) error {
|
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()
|
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
|
delay := time.Duration(int(math.Pow(2, float64(attempt)))) * time.Second
|
||||||
if retryOptions.Delay != 0 {
|
if options.Delay != 0 {
|
||||||
delay = retryOptions.Delay
|
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 {
|
select {
|
||||||
case <-time.After(delay):
|
case <-time.After(delay):
|
||||||
break
|
break
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue