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.
61 lines
1.4 KiB
61 lines
1.4 KiB
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"pure-admin/global"
|
|
"pure-admin/utils"
|
|
"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 MissionStatisticTask struct {
|
|
}
|
|
|
|
func (t MissionStatisticTask) Run() {
|
|
err, result := RedisSetNX("mission_statistic_task", "used", 10*time.Minute)
|
|
result = true
|
|
if err == nil && result {
|
|
fmt.Println("任务执行")
|
|
_ = MissionStatisticCountTotal()
|
|
fmt.Println("任务执行完成")
|
|
}
|
|
}
|
|
|
|
type MissionStatisticTaskDaily struct {
|
|
}
|
|
|
|
func (t MissionStatisticTaskDaily) Run() {
|
|
|
|
err, result := RedisSetNX("mission_statistic_task_daily", "used", 10*time.Minute)
|
|
result = true
|
|
if err == nil && result {
|
|
fmt.Println("任务执行")
|
|
_ = MissionStatisticCountDaily(time.Now().AddDate(0, 0, -1).Format(utils.DateFormat))
|
|
fmt.Println("任务执行完成")
|
|
}
|
|
|
|
}
|
|
|
|
func TimingTask() {
|
|
c := newWithSecond()
|
|
var err error
|
|
_, err = c.AddJob("1 */30 * * * *", MissionStatisticTask{})
|
|
if err != nil {
|
|
global.MG_LOG.Error("MissionStatisticCron " + err.Error())
|
|
return
|
|
}
|
|
_, err = c.AddJob("1 0 * * * *", MissionStatisticTaskDaily{})
|
|
if err != nil {
|
|
global.MG_LOG.Error("MissionStatisticDailyCron " + err.Error())
|
|
return
|
|
}
|
|
c.Start()
|
|
fmt.Println("定时任务开启成功")
|
|
}
|
|
|