mirror of
https://github.com/project-zot/zot.git
synced 2024-12-16 21:56:37 -05:00
112fbec5b6
- 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>
24 lines
425 B
Go
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
|
|
}
|