Skip to content

Commit

Permalink
fix: 优化计划任务脚本执行任务输出
Browse files Browse the repository at this point in the history
  • Loading branch information
ssongliu committed Mar 6, 2024
1 parent ca3be03 commit 4e3f5a0
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 20 deletions.
6 changes: 1 addition & 5 deletions backend/app/api/v1/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ func (b *BaseApi) LoadRecordLog(c *gin.Context) {
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
content, err := cronjobService.LoadRecordLog(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
content := cronjobService.LoadRecordLog(req)
helper.SuccessWithData(c, content)
}

Expand Down
13 changes: 6 additions & 7 deletions backend/app/service/cornjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/jinzhu/copier"
Expand All @@ -33,7 +32,7 @@ type ICronjobService interface {
StartJob(cronjob *model.Cronjob) (string, error)
CleanRecord(req dto.CronjobClean) error

LoadRecordLog(req dto.OperateByID) (string, error)
LoadRecordLog(req dto.OperateByID) string
}

func NewICronjobService() ICronjobService {
Expand Down Expand Up @@ -77,19 +76,19 @@ func (u *CronjobService) SearchRecords(search dto.SearchRecord) (int64, interfac
return total, dtoCronjobs, err
}

func (u *CronjobService) LoadRecordLog(req dto.OperateByID) (string, error) {
func (u *CronjobService) LoadRecordLog(req dto.OperateByID) string {
record, err := cronjobRepo.GetRecord(commonRepo.WithByID(req.ID))
if err != nil {
return "", err
return ""
}
if _, err := os.Stat(record.Records); err != nil {
return "", buserr.New("ErrHttpReqNotFound")
return ""
}
content, err := os.ReadFile(record.Records)
if err != nil {
return "", err
return ""
}
return string(content), nil
return string(content)
}

func (u *CronjobService) CleanRecord(req dto.CronjobClean) error {
Expand Down
5 changes: 4 additions & 1 deletion backend/app/service/cronjob_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ func (u *CronjobService) HandleJob(cronjob *model.Cronjob) {
}

if err != nil {
cronjobRepo.EndRecords(record, constant.StatusFailed, err.Error(), string(message))
if len(message) != 0 {
record.Records, _ = mkdirAndWriteFile(cronjob, record.StartTime, message)
}
cronjobRepo.EndRecords(record, constant.StatusFailed, err.Error(), record.Records)
return
}
if len(message) != 0 {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ const message = {
database: 'Backup database',
missBackupAccount: 'The backup account could not be found',
syncDate: 'Synchronization time ',
releaseMemory: 'Free memory',
clean: 'Cache Clean',
curl: 'Access URL',
taskName: 'Cronjob name',
cronSpec: 'Lifecycle',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ const message = {
database: '備份數據庫',
missBackupAccount: '未能找到備份賬號',
syncDate: '同步時間 ',
releaseMemory: '放內存',
clean: '存清理',
curl: '訪 URL',
taskName: '任務名稱',
cronSpec: '執行周期',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ const message = {
database: '备份数据库',
missBackupAccount: '未能找到备份账号',
syncDate: '同步时间 ',
releaseMemory: '放内存',
clean: '存清理',
curl: '访 URL',
taskName: '任务名称',
cronSpec: '执行周期',
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/views/cronjob/record/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,6 @@ const forDetail = async (row: Cronjob.Record) => {
loadRecord(row);
};
const loadRecord = async (row: Cronjob.Record) => {
if (row.status === 'Failed') {
currentRecordDetail.value = row.records;
return;
}
if (row.records) {
const res = await getRecordLog(row.id);
currentRecordDetail.value = res.data;
Expand Down

0 comments on commit 4e3f5a0

Please sign in to comment.