39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package task
|
|
|
|
import (
|
|
"github.com/go-co-op/gocron"
|
|
"go.uber.org/zap"
|
|
"miniapp/global"
|
|
"time"
|
|
)
|
|
|
|
var WxTask *gocron.Scheduler
|
|
|
|
func InitTask() {
|
|
WxTask = gocron.NewScheduler(time.Local)
|
|
|
|
// 每天凌晨1点执行
|
|
//cjob, err := WxTask.Cron("0 1 * * *").Do(CheckUserSurgeryDate) // 检查用户是否已到手术日期
|
|
cjob, err := WxTask.Every(1).Day().At("04:00").Do(CheckUserSurgeryDate) // 检查用户是否已到手术日期
|
|
if err != nil {
|
|
global.GVA_LOG.Error("检查用户是否已到手术日期定时任务创建失败", zap.Error(err))
|
|
}
|
|
sjob, err := WxTask.Every(1).Day().At("04:00").Do(SendMsg2User)
|
|
if err != nil {
|
|
global.GVA_LOG.Error("发送消息定时任务创建失败", zap.Error(err))
|
|
}
|
|
cjob.Tag("cjbo")
|
|
sjob.Tag("msg")
|
|
//go func() {
|
|
// for {
|
|
// fmt.Println("cjob Next run:", cjob.NextRun())
|
|
// fmt.Println("sjob Next run:", sjob.NextRun())
|
|
// time.Sleep(time.Second)
|
|
// }
|
|
//}()
|
|
// 开启定时任务
|
|
WxTask.StartAsync()
|
|
global.GVA_LOG.Info("定时任务已开启", zap.Any("定时任务状态:", WxTask.IsRunning()))
|
|
global.GVA_LOG.Info("定时任务已开启", zap.Any("任务数量:", WxTask.Len()))
|
|
}
|