Files
crawlab/backend/services/msg_handler/msg_task.go
陈景阳 951f6a9f07 fix
2019-09-25 14:38:46 +08:00

33 lines
609 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package msg_handler
import (
"crawlab/constants"
"crawlab/model"
"crawlab/utils"
"github.com/apex/log"
"runtime/debug"
"time"
)
type Task struct {
msg NodeMessage
}
func (t *Task) Handle() error {
// 取消任务
ch := utils.TaskExecChanMap.ChanBlocked(t.msg.TaskId)
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
}