添加日志打印

This commit is contained in:
陈景阳
2019-09-25 16:19:58 +08:00
parent 613b5eb139
commit 48dcf5a952
3 changed files with 19 additions and 6 deletions

View File

@@ -14,16 +14,23 @@ type Task struct {
}
func (t *Task) Handle() error {
log.Infof("received cancel task msg, task_id: %s", t.msg.TaskId)
// 取消任务
ch := utils.TaskExecChanMap.ChanBlocked(t.msg.TaskId)
if ch != nil {
ch <- constants.TaskCancel
} else {
log.Infof("chan is empty, update status to abnormal")
// 节点可能被重启找不到chan
t, _ := model.GetTask(t.msg.TaskId)
t.Status = constants.StatusCancelled
t.FinishTs = time.Now()
if err := t.Save(); err != nil {
task, err := model.GetTask(t.msg.TaskId)
if err != nil {
log.Errorf("task not found, task_id: %s", t.msg.TaskId)
debug.PrintStack()
return err
}
task.Status = constants.StatusAbnormal
task.FinishTs = time.Now()
if err := task.Save(); err != nil {
debug.PrintStack()
log.Infof("cancel task error: %s", err.Error())
}