Resovle the system artifact schedule issue (#17098)

Scheduling of system artifact depends on the jobservice, where gorountine is used to avoid the circular dependencies between core and jobservice.

Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2022-07-01 14:25:45 +08:00 committed by GitHub
parent 1ac2c10f63
commit 94bf1c0ebd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@ import (
"context"
"flag"
"fmt"
"net/http"
"net/url"
"os"
"os/signal"
@ -25,17 +26,14 @@ import (
"syscall"
"time"
"github.com/goharbor/harbor/src/controller/systemartifact"
"github.com/beego/beego"
"github.com/goharbor/harbor/src/core/session"
"github.com/goharbor/harbor/src/common/dao"
common_http "github.com/goharbor/harbor/src/common/http"
configCtl "github.com/goharbor/harbor/src/controller/config"
_ "github.com/goharbor/harbor/src/controller/event/handler"
"github.com/goharbor/harbor/src/controller/health"
"github.com/goharbor/harbor/src/controller/registry"
"github.com/goharbor/harbor/src/controller/systemartifact"
"github.com/goharbor/harbor/src/core/api"
_ "github.com/goharbor/harbor/src/core/auth/authproxy"
_ "github.com/goharbor/harbor/src/core/auth/db"
@ -44,6 +42,7 @@ import (
_ "github.com/goharbor/harbor/src/core/auth/uaa"
"github.com/goharbor/harbor/src/core/middlewares"
"github.com/goharbor/harbor/src/core/service/token"
"github.com/goharbor/harbor/src/core/session"
"github.com/goharbor/harbor/src/lib/cache"
_ "github.com/goharbor/harbor/src/lib/cache/memory" // memory cache
_ "github.com/goharbor/harbor/src/lib/cache/redis" // redis cache
@ -51,6 +50,7 @@ import (
"github.com/goharbor/harbor/src/lib/log"
"github.com/goharbor/harbor/src/lib/metric"
"github.com/goharbor/harbor/src/lib/orm"
"github.com/goharbor/harbor/src/lib/retry"
tracelib "github.com/goharbor/harbor/src/lib/trace"
"github.com/goharbor/harbor/src/migration"
"github.com/goharbor/harbor/src/pkg/audit"
@ -233,7 +233,25 @@ func main() {
if err != nil {
log.Warningf("oidc.FixEmptySubIss() errors out, error: %v", err)
}
systemartifact.ScheduleCleanupTask(ctx)
// Scheduling of system artifact depends on the jobservice, where gorountine is used to avoid the circular
// dependencies between core and jobservice.
go func() {
url := config.InternalJobServiceURL() + "/api/v1/stats"
checker := health.HTTPStatusCodeHealthChecker(http.MethodGet, url, nil, 60*time.Second, http.StatusOK)
options := []retry.Option{
retry.InitialInterval(time.Millisecond * 500),
retry.MaxInterval(time.Second * 10),
retry.Timeout(time.Minute),
retry.Callback(func(err error, sleep time.Duration) {
log.Debugf("failed to ping %s, retry after %s : %v", url, sleep, err)
}),
}
if err := retry.Retry(checker.Check, options...); err != nil {
log.Errorf("failed to check the jobservice health status: timeout, error: %v", err)
return
}
systemartifact.ScheduleCleanupTask(ctx)
}()
beego.RunWithMiddleWares("", middlewares.MiddleWares()...)
}