fix: add cron task

This commit is contained in:
2023-10-25 17:00:54 +08:00
parent 2ac4bea8ba
commit 66794f91e2
5 changed files with 241 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
package delExpiredNeBackup
package deleteExpiredRecord
import (
"encoding/json"
@@ -24,8 +24,9 @@ type BarProcessor struct {
type BarParams struct {
Duration int `json:"duration"`
ColName string `json:"colName"`
TableName string `json:"tableName"`
ColName string `json:"colName"` // column name of time string
Extras string `json:"extras"` // extras condition for where
}
func (s *BarProcessor) Execute(data any) (any, error) {
@@ -35,7 +36,6 @@ func (s *BarProcessor) Execute(data any) (any, error) {
options := data.(cron.JobData)
sysJob := options.SysJob
var params BarParams
duration := 60
err := json.Unmarshal([]byte(sysJob.TargetParams), &params)
if err != nil {
@@ -66,7 +66,14 @@ func (s *BarProcessor) Execute(data any) (any, error) {
// // 改变任务进度
// s.progress = i
// }
where := fmt.Sprintf("NOW()>ADDDATE(`%s`,interval %d day)", params.ColName, params.Duration)
var where string
if params.Extras == "" {
where = fmt.Sprintf("NOW()>ADDDATE(`%s`,interval %d day)", params.ColName, params.Duration)
} else {
where = fmt.Sprintf("NOW()>ADDDATE(`%s`,interval %d day) and %s", params.ColName, params.Duration, params.Extras)
}
affected, err := dborm.XormDeleteDataByWhere(where, params.TableName)
if err != nil {
// panic(fmt.Sprintf("Failed to XormDeleteDataByWhere:%v", err))