mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-17 04:11:24 +01:00
Optimize fetch manifest loop when handling notification
Signed-off-by: mmpei <peimingming@corp.netease.com>
This commit is contained in:
parent
b9c96f7e56
commit
5dfc3f2402
@ -111,7 +111,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)
|
log.Errorf("Manifest for image %s:%s is not ready, skip the follow up actions.", repository, tag)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -48,14 +48,19 @@ func NewRepositoryClientForUI(username, repository string) (*registry.Repository
|
|||||||
// WaitForManifestReady implements exponential sleeep to wait until manifest is ready in registry.
|
// WaitForManifestReady implements exponential sleeep to wait until manifest is ready in registry.
|
||||||
// This is a workaround for https://github.com/docker/distribution/issues/2625
|
// This is a workaround for https://github.com/docker/distribution/issues/2625
|
||||||
func WaitForManifestReady(repository string, tag string, maxRetry int) bool {
|
func WaitForManifestReady(repository string, tag string, maxRetry int) bool {
|
||||||
// The initial wait interval, hard-coded to 50ms
|
// The initial wait interval, hard-coded to 80ms, interval will be 80ms,200ms,500ms,1.25s,3.124999936s
|
||||||
interval := 50 * time.Millisecond
|
interval := 80 * time.Millisecond
|
||||||
repoClient, err := NewRepositoryClientForUI("harbor-core", repository)
|
repoClient, err := NewRepositoryClientForUI("harbor-core", repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to create repo client.")
|
log.Errorf("Failed to create repo client.")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for i := 0; i < maxRetry; i++ {
|
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)
|
_, exist, err := repoClient.ManifestExist(tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Unexpected error when checking manifest existence, image: %s:%s, error: %v", repository, tag, err)
|
log.Errorf("Unexpected error when checking manifest existence, image: %s:%s, error: %v", repository, tag, err)
|
||||||
@ -64,9 +69,6 @@ func WaitForManifestReady(repository string, tag string, maxRetry int) bool {
|
|||||||
if exist {
|
if exist {
|
||||||
return true
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user