0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00
zot/pkg/common/retry.go
LaurentiuNiculae 112fbec5b6
refactor(cli): added equivalent subcommands for each flag combination under every command (#1674)
- image command is now deprecated in favor of 'images'
- cve command is now deprecated in favor of 'cves'

Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
2023-08-30 20:12:24 +03:00

24 lines
425 B
Go

package common
import (
"context"
"time"
)
func RetryWithContext(ctx context.Context, operation func(attempt int, retryIn time.Duration) error, maxRetries int,
delay time.Duration,
) error {
err := operation(1, delay)
for attempt := 1; err != nil && attempt < maxRetries; attempt++ {
select {
case <-time.After(delay):
case <-ctx.Done():
return err
}
err = operation(attempt+1, delay)
}
return err
}