- 新增authGroup.DELETE("/tasks_by_status", routes.DeleteTaskByStatus) 支持批量删除指定状态的任务

- TaskListRequestData中增加Status字段,支持根据task状态进行筛选
This commit is contained in:
hantmac
2019-12-05 15:12:32 +08:00
parent a864fdd6e1
commit 07ce8e25fd
4 changed files with 57 additions and 2 deletions

View File

@@ -158,6 +158,8 @@ func GetTask(id string) (Task, error) {
return task, nil
}
func AddTask(item Task) error {
s, c := database.GetCol("tasks")
defer s.Close()
@@ -187,6 +189,20 @@ func RemoveTask(id string) error {
return nil
}
func RemoveTaskByStatus(status string) error {
tasks, err := GetTaskList(bson.M{"status": status}, 0, constants.Infinite, "-create_ts")
if err != nil {
log.Error("get tasks error:" + err.Error())
}
for _, task := range tasks {
if err := RemoveTask(task.Id); err != nil {
log.Error("remove task error:" + err.Error())
continue
}
}
return nil
}
// 删除task by spider_id
func RemoveTaskBySpiderId(id bson.ObjectId) error {
tasks, err := GetTaskList(bson.M{"spider_id": id}, 0, constants.Infinite, "-create_ts")