Improve retry behavior for push operation (#1578)

* Update go-containerregistry to 0.4

* Implement --push-retry argument
This commit is contained in:
Sascha Schwarze
2021-02-22 21:25:58 -08:00
committed by GitHub
parent 2d4db8e0ec
commit 69f942f751
772 changed files with 79840 additions and 23995 deletions
+18
View File
@@ -22,12 +22,15 @@ import (
"encoding/hex"
"io"
"io/ioutil"
"math"
"os"
"strconv"
"sync"
"syscall"
"time"
"github.com/minio/highwayhash"
"github.com/sirupsen/logrus"
)
// Hasher returns a hash function, used in snapshotting to determine if a file has changed
@@ -154,3 +157,18 @@ func GetInputFrom(r io.Reader) ([]byte, error) {
}
return output, nil
}
type retryFunc func() error
// Retry retries an operation
func Retry(operation retryFunc, retryCount int, initialDelayMilliseconds int) error {
err := operation()
for i := 0; err != nil && i < retryCount; i++ {
sleepDuration := time.Millisecond * time.Duration(int(math.Pow(2, float64(i)))*initialDelayMilliseconds)
logrus.Warnf("Retrying operation after %s due to %v", sleepDuration, err)
time.Sleep(sleepDuration)
err = operation()
}
return err
}