diff --git a/src/core/router.go b/src/core/router.go index 5fb8e5aa8..71f7cd215 100644 --- a/src/core/router.go +++ b/src/core/router.go @@ -131,6 +131,7 @@ func initRouters() { beego.Router("/service/notifications/jobs/adminjob/:id([0-9]+)", &admin.Handler{}, "post:HandleAdminJob") beego.Router("/service/notifications/jobs/replication/:id([0-9]+)", &jobs.Handler{}, "post:HandleReplicationScheduleJob") beego.Router("/service/notifications/jobs/replication/task/:id([0-9]+)", &jobs.Handler{}, "post:HandleReplicationTask") + beego.Router("/service/notifications/jobs/retention/task/:id([0-9]+)", &jobs.Handler{}, "post:HandleRetentionTask") beego.Router("/service/notifications/schedules/:id([0-9]+)", &scheduler.Handler{}, "post:Handle") beego.Router("/service/token", &token.Handler{}) diff --git a/src/core/service/notifications/jobs/handler.go b/src/core/service/notifications/jobs/handler.go index 2ddf06b27..4509bfdd2 100644 --- a/src/core/service/notifications/jobs/handler.go +++ b/src/core/service/notifications/jobs/handler.go @@ -16,6 +16,9 @@ package jobs import ( "encoding/json" + "time" + + "github.com/goharbor/harbor/src/pkg/retention" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/job" @@ -97,7 +100,27 @@ func (h *Handler) HandleReplicationScheduleJob() { func (h *Handler) HandleReplicationTask() { log.Debugf("received replication task status update event: task-%d, status-%s", h.id, h.status) if err := hook.UpdateTask(replication.OperationCtl, h.id, h.rawStatus); err != nil { - log.Errorf("Failed to update replication task status, id: %d, status: %s", h.id, h.status) + log.Errorf("failed to update the status of the replication task %d: %v", h.id, err) + h.SendInternalServerError(err) + return + } +} + +// HandleRetentionTask handles the webhook of retention task +func (h *Handler) HandleRetentionTask() { + log.Debugf("received retention task status update event: task-%d, status-%s", h.id, h.status) + mgr := &retention.DefaultManager{} + props := []string{"Status"} + task := &retention.Task{ + ID: h.id, + Status: h.status, + } + if h.status == models.JobFinished { + task.EndTime = time.Now() + } + props = append(props, "EndTime") + if err := mgr.UpdateTask(task, props...); err != nil { + log.Errorf("failed to update the status of retention task %d: %v", h.id, err) h.SendInternalServerError(err) return }