Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 57b76d9

Browse files
fix: Optimize task log tracking mechanism (1Panel-dev#9704)
1 parent 28d8210 commit 57b76d9

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

‎agent/app/dto/response/file.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package response
22

33
import (
4-
"github.com/1Panel-dev/1Panel/agent/utils/files"
54
"time"
5+
6+
"github.com/1Panel-dev/1Panel/agent/utils/files"
67
)
78

89
type FileInfo struct {
@@ -37,11 +38,12 @@ type FileWgetRes struct {
3738
}
3839

3940
type FileLineContent struct {
40-
Content string `json:"content"`
41-
End bool `json:"end"`
42-
Path string `json:"path"`
43-
Total int `json:"total"`
44-
Lines []string `json:"lines"`
41+
Content string `json:"content"`
42+
End bool `json:"end"`
43+
Path string `json:"path"`
44+
Total int `json:"total"`
45+
TaskStatus string `json:"taskStatus"`
46+
Lines []string `json:"lines"`
4547
}
4648

4749
type FileExist struct {

‎agent/app/service/file.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import (
44
"bufio"
55
"context"
66
"fmt"
7-
"github.com/1Panel-dev/1Panel/agent/app/dto"
8-
"github.com/jinzhu/copier"
9-
"golang.org/x/text/encoding"
10-
"golang.org/x/text/encoding/simplifiedchinese"
117
"io"
128
"io/fs"
139
"os"
@@ -20,6 +16,11 @@ import (
2016
"time"
2117
"unicode/utf8"
2218

19+
"github.com/1Panel-dev/1Panel/agent/app/dto"
20+
"github.com/jinzhu/copier"
21+
"golang.org/x/text/encoding"
22+
"golang.org/x/text/encoding/simplifiedchinese"
23+
2324
"github.com/1Panel-dev/1Panel/agent/app/repo"
2425

2526
"github.com/1Panel-dev/1Panel/agent/app/dto/request"
@@ -478,6 +479,7 @@ func (f *FileService) DepthDirSize(req request.DirSizeReq) ([]response.DepthDirS
478479

479480
func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.FileLineContent, error) {
480481
logFilePath := ""
482+
taskStatus := ""
481483
switch req.Type {
482484
case constant.TypeWebsite:
483485
website, err := websiteRepo.GetFirst(repo.WithByID(req.ID))
@@ -533,6 +535,7 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi
533535
return nil, err
534536
}
535537
logFilePath = taskModel.LogFile
538+
taskStatus = taskModel.Status
536539
case "mysql-slow-logs":
537540
logFilePath = path.Join(global.Dir.DataDir, fmt.Sprintf("apps/mysql/%s/data/1Panel-slow.log", req.Name))
538541
case "mariadb-slow-logs":
@@ -551,11 +554,12 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi
551554
lines = append(preLines, lines...)
552555
}
553556
res := &response.FileLineContent{
554-
Content: strings.Join(lines, "\n"),
555-
End: isEndOfFile,
556-
Path: logFilePath,
557-
Total: total,
558-
Lines: lines,
557+
Content: strings.Join(lines, "\n"),
558+
End: isEndOfFile,
559+
Path: logFilePath,
560+
Total: total,
561+
TaskStatus: taskStatus,
562+
Lines: lines,
559563
}
560564
return res, nil
561565
}

‎frontend/src/components/log/file/index.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<template>
22
<div v-loading="firstLoading">
33
<div v-if="defaultButton">
4-
<el-checkbox border v-model="tailLog" class="float-left" @change="changeTail(false)" v-if="showTail">
4+
<el-checkbox
5+
border
6+
:disabled="isTailDisabled"
7+
v-model="tailLog"
8+
class="float-left"
9+
@change="changeTail(false)"
10+
v-if="showTail"
11+
>
512
{{ $t('commons.button.watch') }}
613
</el-checkbox>
714
<el-button
@@ -129,6 +136,8 @@ const minPage = ref(0);
129136
let timer: NodeJS.Timer | null = null;
130137
const logPath = ref('');
131138
139+
const isTailDisabled = ref();
140+
132141
const firstLoading = ref(false);
133142
const logs = ref<string[]>([]);
134143
const logContainer = ref<HTMLElement | null>(null);
@@ -213,6 +222,10 @@ const getContent = async (pre: boolean) => {
213222
firstLoading.value = false;
214223
}
215224
225+
if (res.data.taskStatus && res.data.taskStatus !== 'Executing') {
226+
isTailDisabled.value = true;
227+
}
228+
216229
logPath.value = res.data.path;
217230
firstLoading.value = false;
218231
@@ -330,6 +343,7 @@ const containerStyle = computed(() => ({
330343
331344
onMounted(async () => {
332345
logs.value = [];
346+
isTailDisabled.value = false;
333347
firstLoading.value = true;
334348
await init();
335349
nextTick(() => {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /