mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-08 03:30:51 +01:00
Merge pull request #8385 from ywk253100/190724_task_hook
Implement the webhook handler for retention task
This commit is contained in:
commit
cd411f6588
@ -131,6 +131,7 @@ func initRouters() {
|
|||||||
beego.Router("/service/notifications/jobs/adminjob/:id([0-9]+)", &admin.Handler{}, "post:HandleAdminJob")
|
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/: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/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/notifications/schedules/:id([0-9]+)", &scheduler.Handler{}, "post:Handle")
|
||||||
beego.Router("/service/token", &token.Handler{})
|
beego.Router("/service/token", &token.Handler{})
|
||||||
|
|
||||||
|
@ -16,6 +16,9 @@ package jobs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/pkg/retention"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/job"
|
"github.com/goharbor/harbor/src/common/job"
|
||||||
@ -97,7 +100,27 @@ func (h *Handler) HandleReplicationScheduleJob() {
|
|||||||
func (h *Handler) HandleReplicationTask() {
|
func (h *Handler) HandleReplicationTask() {
|
||||||
log.Debugf("received replication task status update event: task-%d, status-%s", h.id, h.status)
|
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 {
|
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)
|
h.SendInternalServerError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user