fix: add cron task
This commit is contained in:
@@ -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), ¶ms)
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user