mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-27 04:35:16 +01:00
support stop in the retention job and register it
Signed-off-by: Steven Zou <szou@vmware.com>
This commit is contained in:
parent
6401314a3d
commit
ccad9c0a29
@ -17,14 +17,16 @@ package runtime
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/goharbor/harbor/src/jobservice/mgt"
|
||||
"github.com/goharbor/harbor/src/jobservice/migration"
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/goharbor/harbor/src/jobservice/mgt"
|
||||
"github.com/goharbor/harbor/src/jobservice/migration"
|
||||
"github.com/goharbor/harbor/src/pkg/retention"
|
||||
|
||||
"github.com/goharbor/harbor/src/jobservice/api"
|
||||
"github.com/goharbor/harbor/src/jobservice/common/utils"
|
||||
"github.com/goharbor/harbor/src/jobservice/config"
|
||||
@ -243,6 +245,7 @@ func (bs *Bootstrap) loadAndRunRedisWorkerPool(
|
||||
job.ImageGC: (*gc.GarbageCollector)(nil),
|
||||
job.Replication: (*replication.Replication)(nil),
|
||||
job.ReplicationScheduler: (*replication.Scheduler)(nil),
|
||||
job.Retention: (*retention.Job)(nil),
|
||||
}); err != nil {
|
||||
// exit
|
||||
return nil, err
|
||||
|
@ -16,6 +16,7 @@ package retention
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/goharbor/harbor/src/jobservice/job"
|
||||
"github.com/goharbor/harbor/src/jobservice/logger"
|
||||
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
||||
@ -63,6 +64,12 @@ func (pj *Job) Run(ctx job.Context, params job.Parameters) error {
|
||||
repo, _ := getParamRepo(params)
|
||||
liteMeta, _ := getParamMeta(params)
|
||||
|
||||
// Stop check point 1:
|
||||
if isStopped(ctx) {
|
||||
logStop(myLogger)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Retrieve all the candidates under the specified repository
|
||||
allCandidates, err := pj.client.GetCandidates(repo)
|
||||
if err != nil {
|
||||
@ -76,6 +83,12 @@ func (pj *Job) Run(ctx job.Context, params job.Parameters) error {
|
||||
return logError(myLogger, err)
|
||||
}
|
||||
|
||||
// Stop check point 2:
|
||||
if isStopped(ctx) {
|
||||
logStop(myLogger)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run the flow
|
||||
results, err := processor.Process(allCandidates)
|
||||
if err != nil {
|
||||
@ -95,6 +108,17 @@ func (pj *Job) Run(ctx job.Context, params job.Parameters) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func isStopped(ctx job.Context) (stopped bool) {
|
||||
cmd, ok := ctx.OPCommand()
|
||||
stopped = ok && cmd == job.StopCommand
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func logStop(logger logger.Interface) {
|
||||
logger.Info("Retention job is stopped")
|
||||
}
|
||||
|
||||
func logError(logger logger.Interface, err error) error {
|
||||
wrappedErr := errors.Wrap(err, "retention job")
|
||||
logger.Error(wrappedErr)
|
||||
|
Loading…
Reference in New Issue
Block a user