fix: crontask for delete ne backup file
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
package delExpiredNeBackup
|
package delExpiredNeBackup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"ems.agt/lib/dborm"
|
"ems.agt/lib/dborm"
|
||||||
"ems.agt/lib/log"
|
"ems.agt/lib/log"
|
||||||
"ems.agt/src/framework/cron"
|
"ems.agt/src/framework/cron"
|
||||||
@@ -19,12 +22,23 @@ type BarProcessor struct {
|
|||||||
count int
|
count int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BarParams struct {
|
||||||
|
Duration int `json:"duration"`
|
||||||
|
}
|
||||||
|
|
||||||
func (s *BarProcessor) Execute(data any) (any, error) {
|
func (s *BarProcessor) Execute(data any) (any, error) {
|
||||||
log.Infof("执行 %d 次,上次进度: %d ", s.count, s.progress)
|
log.Infof("执行 %d 次,上次进度: %d ", s.count, s.progress)
|
||||||
s.count++
|
s.count++
|
||||||
|
|
||||||
options := data.(cron.JobData)
|
options := data.(cron.JobData)
|
||||||
sysJob := options.SysJob
|
sysJob := options.SysJob
|
||||||
|
var params BarParams
|
||||||
|
duration := 60
|
||||||
|
|
||||||
|
err := json.Unmarshal([]byte(sysJob.TargetParams), ¶ms)
|
||||||
|
if err == nil {
|
||||||
|
duration = params.Duration
|
||||||
|
}
|
||||||
log.Infof("重复 %v 任务ID %s", options.Repeat, sysJob.JobID)
|
log.Infof("重复 %v 任务ID %s", options.Repeat, sysJob.JobID)
|
||||||
|
|
||||||
// // 实现任务处理逻辑
|
// // 实现任务处理逻辑
|
||||||
@@ -48,16 +62,19 @@ func (s *BarProcessor) Execute(data any) (any, error) {
|
|||||||
// // 改变任务进度
|
// // 改变任务进度
|
||||||
// s.progress = i
|
// s.progress = i
|
||||||
// }
|
// }
|
||||||
where := "NOW()>ADDDATE(`create_time`,interval IFNULL((SELECT `value` FROM config WHERE config_tag='BackUpSaveTime'),30) day)"
|
where := fmt.Sprintf("NOW()>ADDDATE(`create_time`,interval %d day)", duration)
|
||||||
affected, err := dborm.XormDeleteDataByWhere(where, "ne_backup")
|
affected, err := dborm.XormDeleteDataByWhere(where, "ne_backup")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// panic(fmt.Sprintf("Failed to XormDeleteDataByWhere:%v", err))
|
// panic(fmt.Sprintf("Failed to XormDeleteDataByWhere:%v", err))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// delete expired files in backup directory
|
||||||
|
// todo ...
|
||||||
|
|
||||||
// 返回结果,用于记录执行结果
|
// 返回结果,用于记录执行结果
|
||||||
return map[string]any{
|
return map[string]any{
|
||||||
"msg": "sucesse",
|
"msg": "sucess",
|
||||||
"affected": affected,
|
"affected": affected,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user