mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-17 03:04:46 +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 {
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
content, err := cronjobService.LoadRecordLog(req)
|
content := cronjobService.LoadRecordLog(req)
|
||||||
if err != nil {
|
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
helper.SuccessWithData(c, content)
|
helper.SuccessWithData(c, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/model"
|
"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/constant"
|
||||||
"github.com/1Panel-dev/1Panel/backend/global"
|
"github.com/1Panel-dev/1Panel/backend/global"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
@ -33,7 +32,7 @@ type ICronjobService interface {
|
|||||||
StartJob(cronjob *model.Cronjob) (string, error)
|
StartJob(cronjob *model.Cronjob) (string, error)
|
||||||
CleanRecord(req dto.CronjobClean) error
|
CleanRecord(req dto.CronjobClean) error
|
||||||
|
|
||||||
LoadRecordLog(req dto.OperateByID) (string, error)
|
LoadRecordLog(req dto.OperateByID) string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewICronjobService() ICronjobService {
|
func NewICronjobService() ICronjobService {
|
||||||
@ -77,19 +76,19 @@ func (u *CronjobService) SearchRecords(search dto.SearchRecord) (int64, interfac
|
|||||||
return total, dtoCronjobs, err
|
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))
|
record, err := cronjobRepo.GetRecord(commonRepo.WithByID(req.ID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return ""
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(record.Records); err != nil {
|
if _, err := os.Stat(record.Records); err != nil {
|
||||||
return "", buserr.New("ErrHttpReqNotFound")
|
return ""
|
||||||
}
|
}
|
||||||
content, err := os.ReadFile(record.Records)
|
content, err := os.ReadFile(record.Records)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return ""
|
||||||
}
|
}
|
||||||
return string(content), nil
|
return string(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *CronjobService) CleanRecord(req dto.CronjobClean) error {
|
func (u *CronjobService) CleanRecord(req dto.CronjobClean) error {
|
||||||
|
@ -82,7 +82,10 @@ func (u *CronjobService) HandleJob(cronjob *model.Cronjob) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
if len(message) != 0 {
|
if len(message) != 0 {
|
||||||
|
@ -806,7 +806,7 @@ const message = {
|
|||||||
database: 'Backup database',
|
database: 'Backup database',
|
||||||
missBackupAccount: 'The backup account could not be found',
|
missBackupAccount: 'The backup account could not be found',
|
||||||
syncDate: 'Synchronization time ',
|
syncDate: 'Synchronization time ',
|
||||||
releaseMemory: 'Free memory',
|
clean: 'Cache Clean',
|
||||||
curl: 'Access URL',
|
curl: 'Access URL',
|
||||||
taskName: 'Cronjob name',
|
taskName: 'Cronjob name',
|
||||||
cronSpec: 'Lifecycle',
|
cronSpec: 'Lifecycle',
|
||||||
|
@ -768,7 +768,7 @@ const message = {
|
|||||||
database: '備份數據庫',
|
database: '備份數據庫',
|
||||||
missBackupAccount: '未能找到備份賬號',
|
missBackupAccount: '未能找到備份賬號',
|
||||||
syncDate: '同步時間 ',
|
syncDate: '同步時間 ',
|
||||||
releaseMemory: '釋放內存',
|
clean: '缓存清理',
|
||||||
curl: '訪問 URL',
|
curl: '訪問 URL',
|
||||||
taskName: '任務名稱',
|
taskName: '任務名稱',
|
||||||
cronSpec: '執行周期',
|
cronSpec: '執行周期',
|
||||||
|
@ -769,7 +769,7 @@ const message = {
|
|||||||
database: '备份数据库',
|
database: '备份数据库',
|
||||||
missBackupAccount: '未能找到备份账号',
|
missBackupAccount: '未能找到备份账号',
|
||||||
syncDate: '同步时间 ',
|
syncDate: '同步时间 ',
|
||||||
releaseMemory: '释放内存',
|
clean: '缓存清理',
|
||||||
curl: '访问 URL',
|
curl: '访问 URL',
|
||||||
taskName: '任务名称',
|
taskName: '任务名称',
|
||||||
cronSpec: '执行周期',
|
cronSpec: '执行周期',
|
||||||
|
@ -405,10 +405,6 @@ const forDetail = async (row: Cronjob.Record) => {
|
|||||||
loadRecord(row);
|
loadRecord(row);
|
||||||
};
|
};
|
||||||
const loadRecord = async (row: Cronjob.Record) => {
|
const loadRecord = async (row: Cronjob.Record) => {
|
||||||
if (row.status === 'Failed') {
|
|
||||||
currentRecordDetail.value = row.records;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (row.records) {
|
if (row.records) {
|
||||||
const res = await getRecordLog(row.id);
|
const res = await getRecordLog(row.id);
|
||||||
currentRecordDetail.value = res.data;
|
currentRecordDetail.value = res.data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user