mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 10:45:45 +01:00
Implement the webhook handler for retention task
Implement the webhook handler for retention task Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
parent
9437b489ac
commit
e2808f12cf
@ -132,6 +132,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{})
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user