This commit is contained in:
陈景阳
2019-09-25 14:38:46 +08:00
parent f3fd19d198
commit fe221ffd6f
5 changed files with 76 additions and 9 deletions

View File

@@ -2,7 +2,11 @@ package msg_handler
import (
"crawlab/constants"
"crawlab/model"
"crawlab/utils"
"github.com/apex/log"
"runtime/debug"
"time"
)
type Task struct {
@@ -12,6 +16,17 @@ type Task struct {
func (t *Task) Handle() error {
// 取消任务
ch := utils.TaskExecChanMap.ChanBlocked(t.msg.TaskId)
ch <- constants.TaskCancel
if ch != nil {
ch <- constants.TaskCancel
} else {
// 节点可能被重启找不到chan
t, _ := model.GetTask(t.msg.TaskId)
t.Status = constants.StatusCancelled
t.FinishTs = time.Now()
if err := t.Save(); err != nil {
debug.PrintStack()
log.Infof("cancel task error: %s", err.Error())
}
}
return nil
}