From 57b76d97ec2ce2eb206a01e6197995abad4cd944 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Mon, 28 Jul 2025 17:12:42 +0800 Subject: [PATCH] fix: Optimize task log tracking mechanism (#9704) --- agent/app/dto/response/file.go | 14 ++++++++------ agent/app/service/file.go | 22 +++++++++++++--------- frontend/src/components/log/file/index.vue | 16 +++++++++++++++- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/agent/app/dto/response/file.go b/agent/app/dto/response/file.go index a85366219..c7e5702ae 100644 --- a/agent/app/dto/response/file.go +++ b/agent/app/dto/response/file.go @@ -1,8 +1,9 @@ package response import ( - "github.com/1Panel-dev/1Panel/agent/utils/files" "time" + + "github.com/1Panel-dev/1Panel/agent/utils/files" ) type FileInfo struct { @@ -37,11 +38,12 @@ type FileWgetRes struct { } type FileLineContent struct { - Content string `json:"content"` - End bool `json:"end"` - Path string `json:"path"` - Total int `json:"total"` - Lines []string `json:"lines"` + Content string `json:"content"` + End bool `json:"end"` + Path string `json:"path"` + Total int `json:"total"` + TaskStatus string `json:"taskStatus"` + Lines []string `json:"lines"` } type FileExist struct { diff --git a/agent/app/service/file.go b/agent/app/service/file.go index ef2f68824..66f321b01 100644 --- a/agent/app/service/file.go +++ b/agent/app/service/file.go @@ -4,10 +4,6 @@ import ( "bufio" "context" "fmt" - "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/jinzhu/copier" - "golang.org/x/text/encoding" - "golang.org/x/text/encoding/simplifiedchinese" "io" "io/fs" "os" @@ -20,6 +16,11 @@ import ( "time" "unicode/utf8" + "github.com/1Panel-dev/1Panel/agent/app/dto" + "github.com/jinzhu/copier" + "golang.org/x/text/encoding" + "golang.org/x/text/encoding/simplifiedchinese" + "github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/app/dto/request" @@ -478,6 +479,7 @@ func (f *FileService) DepthDirSize(req request.DirSizeReq) ([]response.DepthDirS func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.FileLineContent, error) { logFilePath := "" + taskStatus := "" switch req.Type { case constant.TypeWebsite: website, err := websiteRepo.GetFirst(repo.WithByID(req.ID)) @@ -533,6 +535,7 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi return nil, err } logFilePath = taskModel.LogFile + taskStatus = taskModel.Status case "mysql-slow-logs": logFilePath = path.Join(global.Dir.DataDir, fmt.Sprintf("apps/mysql/%s/data/1Panel-slow.log", req.Name)) case "mariadb-slow-logs": @@ -551,11 +554,12 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi lines = append(preLines, lines...) } res := &response.FileLineContent{ - Content: strings.Join(lines, "\n"), - End: isEndOfFile, - Path: logFilePath, - Total: total, - Lines: lines, + Content: strings.Join(lines, "\n"), + End: isEndOfFile, + Path: logFilePath, + Total: total, + TaskStatus: taskStatus, + Lines: lines, } return res, nil } diff --git a/frontend/src/components/log/file/index.vue b/frontend/src/components/log/file/index.vue index 37d57e55a..938e8b8b0 100644 --- a/frontend/src/components/log/file/index.vue +++ b/frontend/src/components/log/file/index.vue @@ -1,7 +1,14 @@