You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gojobs/check_task.go

42 lines
1.4 KiB

2 years ago
package gojobs
2 years ago
import (
2 years ago
"context"
2 years ago
"go.dtapp.net/gojobs/jobs_gorm_model"
2 years ago
"go.dtapp.net/gotime"
"gorm.io/gorm"
"log"
)
2 years ago
// CheckManyTask 多任务检查
2 years ago
func (c *Client) CheckManyTask(ctx context.Context, tx *gorm.DB, vs []jobs_gorm_model.Task) {
2 years ago
if len(vs) > 0 {
2 years ago
for _, v := range vs {
2 years ago
diffInSecondWithAbs := gotime.Current().DiffInSecondWithAbs(gotime.SetCurrent(v.UpdatedAt).Time)
2 years ago
if diffInSecondWithAbs >= v.Frequency*3 {
2 years ago
if c.config.debug == true {
log.Printf("[jobs.CheckManyTask]每隔%v秒任务%v相差%v秒\n", v.Frequency, v.Id, diffInSecondWithAbs)
2 years ago
}
err := tx.Where("task_id = ?", v.Id).Where("run_id = ?", v.RunId).Delete(&jobs_gorm_model.TaskLogRun{}).Error
if err != nil {
log.Println("删除失败", err.Error())
2 years ago
}
2 years ago
}
}
}
}
2 years ago
// CheckSingleTask 单任务检查
2 years ago
func (c *Client) CheckSingleTask(ctx context.Context, tx *gorm.DB, v jobs_gorm_model.Task) {
2 years ago
diffInSecondWithAbs := gotime.Current().DiffInSecondWithAbs(gotime.SetCurrent(v.UpdatedAt).Time)
2 years ago
if diffInSecondWithAbs >= v.Frequency*3 {
2 years ago
if c.config.debug == true {
log.Printf("[jobs.CheckManyTask]每隔%v秒任务%v相差%v秒\n", v.Frequency, v.Id, diffInSecondWithAbs)
2 years ago
}
err := tx.Where("task_id = ?", v.Id).Where("run_id = ?", v.RunId).Delete(&jobs_gorm_model.TaskLogRun{}).Error
if err != nil {
log.Println("删除失败", err.Error())
2 years ago
}
}
}