mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +08:00
fix: 优化计划任务脚本执行输出 (#4080)
This commit is contained in:
parent
ca3be03ae7
commit
a99f19471b
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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',
|
||||
|
@ -768,7 +768,7 @@ const message = {
|
||||
database: '備份數據庫',
|
||||
missBackupAccount: '未能找到備份賬號',
|
||||
syncDate: '同步時間 ',
|
||||
releaseMemory: '釋放內存',
|
||||
clean: '缓存清理',
|
||||
curl: '訪問 URL',
|
||||
taskName: '任務名稱',
|
||||
cronSpec: '執行周期',
|
||||
|
@ -769,7 +769,7 @@ const message = {
|
||||
database: '备份数据库',
|
||||
missBackupAccount: '未能找到备份账号',
|
||||
syncDate: '同步时间 ',
|
||||
releaseMemory: '释放内存',
|
||||
clean: '缓存清理',
|
||||
curl: '访问 URL',
|
||||
taskName: '任务名称',
|
||||
cronSpec: '执行周期',
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user