mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 18:25:56 +01:00
Merge pull request #8189 from mmpei/8162-optimize-manifest-wait
Optimize fetch manifest loop when handling notification
This commit is contained in:
commit
b0c8561b54
@ -112,7 +112,7 @@ func (n *NotificationHandler) Post() {
|
||||
}()
|
||||
}
|
||||
|
||||
if !coreutils.WaitForManifestReady(repository, tag, 5) {
|
||||
if !coreutils.WaitForManifestReady(repository, tag, 6) {
|
||||
log.Errorf("Manifest for image %s:%s is not ready, skip the follow up actions.", repository, tag)
|
||||
return
|
||||
}
|
||||
|
@ -62,14 +62,19 @@ func newRepositoryClient(endpoint, username, repository string) (*registry.Repos
|
||||
// WaitForManifestReady implements exponential sleeep to wait until manifest is ready in registry.
|
||||
// This is a workaround for https://github.com/docker/distribution/issues/2625
|
||||
func WaitForManifestReady(repository string, tag string, maxRetry int) bool {
|
||||
// The initial wait interval, hard-coded to 50ms
|
||||
interval := 50 * time.Millisecond
|
||||
// The initial wait interval, hard-coded to 80ms, interval will be 80ms,200ms,500ms,1.25s,3.124999936s
|
||||
interval := 80 * time.Millisecond
|
||||
repoClient, err := NewRepositoryClientForUI("harbor-core", repository)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to create repo client.")
|
||||
return false
|
||||
}
|
||||
for i := 0; i < maxRetry; i++ {
|
||||
if i != 0 {
|
||||
log.Warningf("manifest for image %s:%s is not ready, retry after %v", repository, tag, interval)
|
||||
time.Sleep(interval)
|
||||
interval = time.Duration(int64(float32(interval) * 2.5))
|
||||
}
|
||||
_, exist, err := repoClient.ManifestExist(tag)
|
||||
if err != nil {
|
||||
log.Errorf("Unexpected error when checking manifest existence, image: %s:%s, error: %v", repository, tag, err)
|
||||
@ -78,9 +83,6 @@ func WaitForManifestReady(repository string, tag string, maxRetry int) bool {
|
||||
if exist {
|
||||
return true
|
||||
}
|
||||
log.Warningf("manifest for image %s:%s is not ready, retry after %v", repository, tag, interval)
|
||||
time.Sleep(interval)
|
||||
interval = interval * 2
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user