diff --git a/backend/entity/common.go b/backend/entity/common.go index 332cc494..c46ae4f9 100644 --- a/backend/entity/common.go +++ b/backend/entity/common.go @@ -3,15 +3,15 @@ package entity import "strconv" type Page struct { - Skip int - Limit int - PageNum int + Skip int + Limit int + PageNum int PageSize int } -func (p *Page)GetPage(pageNum string, pageSize string) { +func (p *Page) GetPage(pageNum string, pageSize string) { p.PageNum, _ = strconv.Atoi(pageNum) p.PageSize, _ = strconv.Atoi(pageSize) p.Skip = p.PageSize * (p.PageNum - 1) p.Limit = p.PageSize -} \ No newline at end of file +} diff --git a/backend/mock/node_test.go b/backend/mock/node_test.go index 669cafc5..abd568c2 100644 --- a/backend/mock/node_test.go +++ b/backend/mock/node_test.go @@ -42,12 +42,12 @@ func init() { app.DELETE("/tasks/:id", DeleteTask) // 删除任务 app.GET("/tasks/:id/results", GetTaskResults) // 任务结果 app.GET("/tasks/:id/results/download", DownloadTaskResultsCsv) // 下载任务结果 - app.GET("/spiders", GetSpiderList) // 爬虫列表 - app.GET("/spiders/:id", GetSpider) // 爬虫详情 - app.POST("/spiders/:id", PostSpider) // 修改爬虫 - app.DELETE("/spiders/:id",DeleteSpider) // 删除爬虫 - app.GET("/spiders/:id/tasks",GetSpiderTasks) // 爬虫任务列表 - app.GET("/spiders/:id/dir",GetSpiderDir) // 爬虫目录 + app.GET("/spiders", GetSpiderList) // 爬虫列表 + app.GET("/spiders/:id", GetSpider) // 爬虫详情 + app.POST("/spiders/:id", PostSpider) // 修改爬虫 + app.DELETE("/spiders/:id", DeleteSpider) // 删除爬虫 + app.GET("/spiders/:id/tasks", GetSpiderTasks) // 爬虫任务列表 + app.GET("/spiders/:id/dir", GetSpiderDir) // 爬虫目录 } //mock test, test data in ./mock diff --git a/backend/mock/stats.go b/backend/mock/stats.go index db2348c6..f0227da9 100644 --- a/backend/mock/stats.go +++ b/backend/mock/stats.go @@ -6,8 +6,6 @@ import ( "net/http" ) - - var taskDailyItems = []model.TaskDailyItem{ { Date: "2019/08/19", diff --git a/backend/mock/system.go b/backend/mock/system.go index c4807247..f33e02ba 100644 --- a/backend/mock/system.go +++ b/backend/mock/system.go @@ -1 +1 @@ -package mock \ No newline at end of file +package mock diff --git a/backend/mock/user.go b/backend/mock/user.go index c4807247..f33e02ba 100644 --- a/backend/mock/user.go +++ b/backend/mock/user.go @@ -1 +1 @@ -package mock \ No newline at end of file +package mock diff --git a/backend/services/task.go b/backend/services/task.go index 0cd53d86..0339118a 100644 --- a/backend/services/task.go +++ b/backend/services/task.go @@ -308,9 +308,12 @@ func SaveTaskResultCount(id string) func() { // 执行任务 func ExecuteTask(id int) { - if flag, _ := LockList.Load(id); flag.(bool) { - log.Debugf(GetWorkerPrefix(id) + "正在执行任务...") - return + if flag, ok := LockList.Load(id); ok { + if flag.(bool) { + log.Debugf(GetWorkerPrefix(id) + "正在执行任务...") + return + } + } // 上锁 @@ -474,6 +477,29 @@ func GetTaskLog(id string) (logStr string, err error) { } if IsMasterNode(task.NodeId.Hex()) { + if !utils.Exists(task.LogPath) { + fileDir, err := MakeLogDir(task) + + if err != nil { + log.Errorf(err.Error()) + } + + fileP := GetLogFilePaths(fileDir) + + // 获取日志文件路径 + fLog, err := os.Create(fileP) + defer fLog.Close() + if err != nil { + log.Errorf("create task log file error: %s", fileP) + debug.PrintStack() + } + task.LogPath = fileP + if err := task.Save(); err != nil { + log.Errorf(err.Error()) + debug.PrintStack() + } + + } // 若为主节点,获取本机日志 logBytes, err := model.GetLocalLog(task.LogPath) if err != nil {