mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/apex/log"
|
||||
"github.com/globalsign/mgo"
|
||||
"github.com/globalsign/mgo/bson"
|
||||
"github.com/imroc/req"
|
||||
"github.com/satori/go.uuid"
|
||||
@@ -608,6 +609,12 @@ func ExecuteTask(id int) {
|
||||
// 储存任务
|
||||
_ = t.Save()
|
||||
|
||||
// 创建结果集索引
|
||||
go func() {
|
||||
col := utils.GetSpiderCol(spider.Col, spider.Name)
|
||||
CreateResultsIndexes(col)
|
||||
}()
|
||||
|
||||
// 起一个cron执行器来统计任务结果数
|
||||
cronExec := cron.New(cron.WithSeconds())
|
||||
_, err = cronExec.AddFunc("*/5 * * * * *", SaveTaskResultCount(t.Id))
|
||||
@@ -971,6 +978,15 @@ func GetTaskMarkdownContent(t model.Task, s model.Spider) string {
|
||||
)
|
||||
}
|
||||
|
||||
func CreateResultsIndexes(col string) {
|
||||
s, c := database.GetCol(col)
|
||||
defer s.Close()
|
||||
|
||||
_ = c.EnsureIndex(mgo.Index{
|
||||
Key: []string{"task_id"},
|
||||
})
|
||||
}
|
||||
|
||||
func SendTaskEmail(u model.User, t model.Task, s model.Spider) {
|
||||
statusMsg := "has finished"
|
||||
if t.Status == constants.StatusError {
|
||||
|
||||
Reference in New Issue
Block a user