fix: crontask for delete ne backup file

This commit is contained in:
2023-10-21 17:00:03 +08:00
parent 217d807ed3
commit 3d55c0f7f9

View File

@@ -1,6 +1,9 @@
package delExpiredNeBackup
import (
"encoding/json"
"fmt"
"ems.agt/lib/dborm"
"ems.agt/lib/log"
"ems.agt/src/framework/cron"
@@ -19,12 +22,23 @@ type BarProcessor struct {
count int
}
type BarParams struct {
Duration int `json:"duration"`
}
func (s *BarProcessor) Execute(data any) (any, error) {
log.Infof("执行 %d 次,上次进度: %d ", s.count, s.progress)
s.count++
options := data.(cron.JobData)
sysJob := options.SysJob
var params BarParams
duration := 60
err := json.Unmarshal([]byte(sysJob.TargetParams), &params)
if err == nil {
duration = params.Duration
}
log.Infof("重复 %v 任务ID %s", options.Repeat, sysJob.JobID)
// // 实现任务处理逻辑
@@ -48,16 +62,19 @@ func (s *BarProcessor) Execute(data any) (any, error) {
// // 改变任务进度
// 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")
if err != nil {
// panic(fmt.Sprintf("Failed to XormDeleteDataByWhere:%v", err))
return nil, err
}
// delete expired files in backup directory
// todo ...
// 返回结果,用于记录执行结果
return map[string]any{
"msg": "sucesse",
"msg": "sucess",
"affected": affected,
}, nil
}