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.

43 lines
910 B

6 months ago
package service
import (
"bkb-seller/global"
"fmt"
"time"
"github.com/robfig/cron/v3"
)
func newWithSecond() *cron.Cron {
secondParser := cron.NewParser(cron.Second | cron.Minute |
cron.Hour | cron.Dom | cron.Month | cron.DowOptional | cron.Descriptor)
return cron.New(cron.WithParser(secondParser), cron.WithChain())
}
type MissionStatusCheck struct {
}
func (t MissionStatusCheck) Run() {
err, result := RedisSetNX("mission_status_check_task", "used", 10*time.Minute)
result = true
if err == nil && result {
fmt.Println("检查任务状态执行")
_ = MissionStatusCheckTask()
fmt.Println("检查任务状态执行完成")
}
}
func TimingTask() {
c := newWithSecond()
var err error
_, err = c.AddJob("1 0 * * * *", MissionStatusCheck{})
if err != nil {
global.MG_LOG.Error("MissionStatusCheck " + err.Error())
return
}
c.Start()
fmt.Println("定时任务开启成功")
}