From 61daf732bd1b4e4a28e9d510b2de95197de18d59 Mon Sep 17 00:00:00 2001 From: hantmac Date: Fri, 29 Nov 2019 13:52:03 +0800 Subject: [PATCH 1/4] =?UTF-8?q?bug=20fix:=E4=BF=AE=E5=A4=8D=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E6=88=96=E8=80=85=E8=87=AA=E5=8A=A8=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=90=8E=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/services/task.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/backend/services/task.go b/backend/services/task.go index 9336e75d..14a609ad 100644 --- a/backend/services/task.go +++ b/backend/services/task.go @@ -468,6 +468,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 { From 1283e0483f367c4282293704735e30012d9abed6 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 1 Dec 2019 18:16:39 +0800 Subject: [PATCH 2/4] chore: fix fmt warning. --- backend/entity/common.go | 10 +++++----- backend/mock/node_test.go | 12 ++++++------ backend/mock/stats.go | 2 -- backend/mock/system.go | 2 +- backend/mock/user.go | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) 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 From 8f06646d99b96023cf6d3c5fb0219ad2b39bd026 Mon Sep 17 00:00:00 2001 From: hantmac Date: Mon, 2 Dec 2019 10:11:57 +0800 Subject: [PATCH 3/4] fix panic because of interface{} is nil --- backend/services/task.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/services/task.go b/backend/services/task.go index 14a609ad..e862c36e 100644 --- a/backend/services/task.go +++ b/backend/services/task.go @@ -302,9 +302,11 @@ 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) + "正在执行任务...") + } + } // 上锁 From 67ae278a66802a43f33570f47a7827ccd6d24891 Mon Sep 17 00:00:00 2001 From: hantmac Date: Mon, 2 Dec 2019 11:14:15 +0800 Subject: [PATCH 4/4] fix --- backend/services/task.go | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/services/task.go b/backend/services/task.go index e862c36e..25b15aeb 100644 --- a/backend/services/task.go +++ b/backend/services/task.go @@ -305,6 +305,7 @@ func ExecuteTask(id int) { if flag, ok := LockList.Load(id); ok { if flag.(bool) { log.Debugf(GetWorkerPrefix(id) + "正在执行任务...") + return } }