diff --git a/agent/app/dto/request/file.go b/agent/app/dto/request/file.go index 5331ed6d6..201d49ae3 100644 --- a/agent/app/dto/request/file.go +++ b/agent/app/dto/request/file.go @@ -135,6 +135,7 @@ type TaskReq struct { TaskID string `json:"taskID"` TaskType string `json:"taskType"` TaskOperate string `json:"taskOperate"` + ResourceID uint `json:"resourceID"` } type FileExistReq struct { diff --git a/agent/app/repo/entry.go b/agent/app/repo/entry.go new file mode 100644 index 000000000..19f73a359 --- /dev/null +++ b/agent/app/repo/entry.go @@ -0,0 +1,5 @@ +package repo + +var ( + commonRepo = NewCommonRepo() +) diff --git a/agent/app/repo/task.go b/agent/app/repo/task.go index b91c2afcc..8e23fe1e7 100644 --- a/agent/app/repo/task.go +++ b/agent/app/repo/task.go @@ -18,6 +18,7 @@ type ITaskRepo interface { GetFirst(opts ...DBOption) (model.Task, error) Page(page, size int, opts ...DBOption) (int64, []model.Task, error) Update(ctx context.Context, task *model.Task) error + UpdateRunningTaskToFailed() error WithByID(id string) DBOption WithResourceID(id uint) DBOption @@ -90,3 +91,7 @@ func (t TaskRepo) Page(page, size int, opts ...DBOption) (int64, []model.Task, e func (t TaskRepo) Update(ctx context.Context, task *model.Task) error { return getTaskTx(ctx).Save(&task).Error } + +func (t TaskRepo) UpdateRunningTaskToFailed() error { + return getTaskDb(commonRepo.WithByStatus(constant.StatusExecuting)).Model(&model.Task{}).Updates(map[string]interface{}{"status": constant.StatusFailed, "error_msg": "1Panel restart causes failure"}).Error +} diff --git a/agent/app/service/nginx.go b/agent/app/service/nginx.go index 53b5cd3dc..8b659687a 100644 --- a/agent/app/service/nginx.go +++ b/agent/app/service/nginx.go @@ -170,6 +170,10 @@ func (n NginxService) Build(req request.NginxBuildReq) error { if err != nil { return err } + taskName := task.GetTaskName(nginxInstall.Name, task.TaskBuild, task.TaskScopeApp) + if err = task.CheckTaskIsExecuting(taskName); err != nil { + return err + } fileOp := files.NewFileOp() buildPath := path.Join(nginxInstall.GetPath(), "build") if !fileOp.Stat(buildPath) { diff --git a/agent/app/service/task.go b/agent/app/service/task.go index ede051344..c733f71a4 100644 --- a/agent/app/service/task.go +++ b/agent/app/service/task.go @@ -9,6 +9,7 @@ type TaskLogService struct{} type ITaskLogService interface { Page(req dto.SearchTaskLogReq) (int64, []dto.TaskDTO, error) + SyncForRestart() error } func NewITaskService() ITaskLogService { @@ -40,3 +41,7 @@ func (u *TaskLogService) Page(req dto.SearchTaskLogReq) (int64, []dto.TaskDTO, e } return total, items, err } + +func (u *TaskLogService) SyncForRestart() error { + return taskRepo.UpdateRunningTaskToFailed() +} diff --git a/agent/app/task/task.go b/agent/app/task/task.go index 6974b4c1a..f025e5554 100644 --- a/agent/app/task/task.go +++ b/agent/app/task/task.go @@ -3,6 +3,7 @@ package task import ( "context" "fmt" + "github.com/1Panel-dev/1Panel/agent/buserr" "log" "os" "path" @@ -75,11 +76,6 @@ const ( TaskScopeRuntimeExtension = "RuntimeExtension" ) -const ( - TaskSuccess = "Success" - TaskFailed = "Failed" -) - func GetTaskName(resourceName, operate, scope string) string { return fmt.Sprintf("%s%s [%s]", i18n.GetMsgByKey(operate), i18n.GetMsgByKey(scope), resourceName) } @@ -88,6 +84,16 @@ func NewTaskWithOps(resourceName, operate, scope, taskID string, resourceID uint return NewTask(GetTaskName(resourceName, operate, scope), operate, scope, taskID, resourceID) } +func CheckTaskIsExecuting(name string) error { + taskRepo := repo.NewITaskRepo() + commonRepo := repo.NewCommonRepo() + task, _ := taskRepo.GetFirst(commonRepo.WithByStatus(constant.StatusExecuting), commonRepo.WithByName(name)) + if task.ID != "" { + return buserr.New("TaskIsExecuting") + } + return nil +} + func NewTask(name, operate, taskScope, taskID string, resourceID uint) (*Task, error) { if taskID == "" { taskID = uuid.New().String() @@ -109,7 +115,7 @@ func NewTask(name, operate, taskScope, taskID string, resourceID uint) (*Task, e Name: name, Type: taskScope, LogFile: logPath, - Status: constant.StatusRunning, + Status: constant.StatusExecuting, ResourceID: resourceID, Operate: operate, } @@ -209,7 +215,7 @@ func (t *Task) Execute() error { break } } - if t.Task.Status == constant.Running { + if t.Task.Status == constant.StatusExecuting { t.Task.Status = constant.StatusSuccess t.Log(i18n.GetWithName("TaskSuccess", t.Name)) } else { diff --git a/agent/constant/status.go b/agent/constant/status.go index 2268cbc32..056e3dcf9 100644 --- a/agent/constant/status.go +++ b/agent/constant/status.go @@ -11,6 +11,7 @@ const ( StatusDisable = "Disable" StatusNone = "None" StatusDeleted = "Deleted" + StatusExecuting = "Executing" OrderDesc = "descending" OrderAsc = "ascending" diff --git a/agent/i18n/lang/en.yaml b/agent/i18n/lang/en.yaml index 32283e417..36afc0699 100644 --- a/agent/i18n/lang/en.yaml +++ b/agent/i18n/lang/en.yaml @@ -291,6 +291,7 @@ TaskSync: "Sync" LocalApp: "Local App" SubTask: "Subtask" RuntimeExtension: "Runtime Extension" +TaskIsExecuting: "Task is executing" # task - snapshot Snapshot: "Snapshot" diff --git a/agent/i18n/lang/zh-Hant.yaml b/agent/i18n/lang/zh-Hant.yaml index a52ba67b3..1e57eecbe 100644 --- a/agent/i18n/lang/zh-Hant.yaml +++ b/agent/i18n/lang/zh-Hant.yaml @@ -292,7 +292,7 @@ TaskSync: "同步" LocalApp: "本地應用" SubTask: "子任務" RuntimeExtension: "運行環境擴展" - +TaskIsExecuting: "任務正在執行中" # task - snapshot Snapshot: "快照" diff --git a/agent/i18n/lang/zh.yaml b/agent/i18n/lang/zh.yaml index a71716842..b0e6a38ea 100644 --- a/agent/i18n/lang/zh.yaml +++ b/agent/i18n/lang/zh.yaml @@ -292,6 +292,7 @@ TaskSync: "同步" LocalApp: "本地应用" SubTask: "子任务" RuntimeExtension: "运行环境扩展" +TaskIsExecuting: "任务正在运行" # task - snapshot Snapshot: "快照" diff --git a/agent/init/business/business.go b/agent/init/business/business.go index 663036fc4..79836c256 100644 --- a/agent/init/business/business.go +++ b/agent/init/business/business.go @@ -11,6 +11,7 @@ func Init() { go syncInstalledApp() go syncRuntime() go syncSSL() + go syncTask() } func syncApp() { @@ -38,3 +39,9 @@ func syncSSL() { global.LOG.Errorf("sync ssl status error : %s", err.Error()) } } + +func syncTask() { + if err := service.NewITaskService().SyncForRestart(); err != nil { + global.LOG.Errorf("sync task status error : %s", err.Error()) + } +} diff --git a/core/app/task/task.go b/core/app/task/task.go index 5f0a5d3e6..9ba08e3e0 100644 --- a/core/app/task/task.go +++ b/core/app/task/task.go @@ -88,7 +88,7 @@ func NewTask(name, operate, taskScope, taskID string, resourceID uint) (*Task, e Name: name, Type: taskScope, LogFile: logPath, - Status: constant.StatusRunning, + Status: constant.StatusExecuting, ResourceID: resourceID, Operate: operate, } @@ -188,7 +188,7 @@ func (t *Task) Execute() error { break } } - if t.Task.Status == constant.StatusRunning { + if t.Task.Status == constant.StatusExecuting { t.Task.Status = constant.StatusSuccess t.Log(i18n.GetWithName("TaskSuccess", t.Name)) } else { diff --git a/core/constant/status.go b/core/constant/status.go index cc5979fde..4dec05640 100644 --- a/core/constant/status.go +++ b/core/constant/status.go @@ -18,6 +18,7 @@ const ( StatusExceptional = "Exceptional" StatusRetrying = "Retrying" StatusLost = "Lost" + StatusExecuting = "Executing" StatusEnable = "Enable" StatusDisable = "Disable" diff --git a/frontend/src/api/interface/file.ts b/frontend/src/api/interface/file.ts index 0ad33750f..d99c1a602 100644 --- a/frontend/src/api/interface/file.ts +++ b/frontend/src/api/interface/file.ts @@ -175,6 +175,9 @@ export namespace File { page: number; pageSize: number; taskID?: string; + taskType?: string; + taskOperate?: string; + resourceID?: number; } export interface Favorite extends CommonModel { diff --git a/frontend/src/components/log-file/index.vue b/frontend/src/components/log-file/index.vue index 70a48b5c9..45e13ea65 100644 --- a/frontend/src/components/log-file/index.vue +++ b/frontend/src/components/log-file/index.vue @@ -34,6 +34,7 @@ interface LogProps { type: string; name?: string; tail?: boolean; + taskID?: string; } const props = defineProps({ @@ -72,6 +73,7 @@ const stopSignals = [ 'image pull successful!', 'image push failed!', 'image push successful!', + '[TASK-END]', ]; const emit = defineEmits(['update:loading', 'update:hasContent', 'update:isReading']); const tailLog = ref(false); @@ -83,6 +85,7 @@ const readReq = reactive({ page: 1, pageSize: 500, latest: false, + taskID: '', }); const isLoading = ref(false); const end = ref(false); @@ -158,6 +161,7 @@ const getContent = async (pre: boolean) => { readReq.id = props.config.id; readReq.type = props.config.type; readReq.name = props.config.name; + readReq.taskID = props.config.taskID; if (readReq.page < 1) { readReq.page = 1; } diff --git a/frontend/src/components/status/index.vue b/frontend/src/components/status/index.vue index 0e9999aee..7cfbc4616 100644 --- a/frontend/src/components/status/index.vue +++ b/frontend/src/components/status/index.vue @@ -47,6 +47,7 @@ const getType = (status: string) => { case 'done': case 'healthy': case 'used': + case 'executing': return 'success'; case 'stopped': case 'exceptional': @@ -80,6 +81,7 @@ const loadingStatus = [ 'packing', 'sending', 'waiting', + 'executing', ]; const loadingIcon = (status: string): boolean => { diff --git a/frontend/src/components/task-log/index.vue b/frontend/src/components/task-log/index.vue index 38c788384..0ec28f348 100644 --- a/frontend/src/components/task-log/index.vue +++ b/frontend/src/components/task-log/index.vue @@ -9,15 +9,12 @@ :width="width" >
- +
- diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 79ab011b3..a293e2c2f 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -301,6 +301,7 @@ const message = { packing: 'Packing', sending: 'Sending', healthy: 'Normal', + executing: 'Executing', }, units: { second: 'Second', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index db6e39a8d..822136ec2 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -296,6 +296,7 @@ const message = { packing: '打包中', sending: '下發中', healthy: '正常', + executing: '執行中', }, units: { second: '秒', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index fc3670abf..468c3ccbd 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -296,6 +296,7 @@ const message = { packing: '打包中', sending: '下发中', healthy: '正常', + executing: '执行中', }, units: { second: '秒', @@ -1165,7 +1166,7 @@ const message = { errLog: '错误日志', task: '任务日志', taskName: '任务名称', - taskRunning: '运行中', + taskRunning: '执行中', }, file: { dir: '文件夹', diff --git a/frontend/src/views/log/task/index.vue b/frontend/src/views/log/task/index.vue index 7f11ad705..ef82f69ea 100644 --- a/frontend/src/views/log/task/index.vue +++ b/frontend/src/views/log/task/index.vue @@ -10,7 +10,7 @@ - +