2024-03-21 21:08:45 +08:00
|
|
|
package task
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-co-op/gocron"
|
2024-03-29 02:32:26 +08:00
|
|
|
"go.uber.org/zap"
|
|
|
|
"miniapp/global"
|
2024-03-21 21:08:45 +08:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var WxTask *gocron.Scheduler
|
|
|
|
|
|
|
|
func InitTask() {
|
|
|
|
WxTask = gocron.NewScheduler(time.Local)
|
|
|
|
|
|
|
|
// 每天凌晨1点执行
|
2024-03-30 22:58:42 +08:00
|
|
|
_, err := WxTask.Every(1).Day().At("01:00").Do(CheckUserSurgeryDate) // 检查用户是否已到手术日期
|
|
|
|
if err != nil {
|
|
|
|
global.GVA_LOG.Error("检查用户是否已到手术日期定时任务创建失败", zap.Error(err))
|
|
|
|
}
|
|
|
|
_, err = WxTask.Every(1).Day().At("01:00").Do(SendMsg2User)
|
|
|
|
if err != nil {
|
|
|
|
global.GVA_LOG.Error("发送消息定时任务创建失败", zap.Error(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = WxTask.Every("1m").Do(SendMsg2User)
|
2024-03-21 21:08:45 +08:00
|
|
|
|
|
|
|
// 开启定时任务
|
|
|
|
WxTask.StartAsync()
|
2024-03-30 22:58:42 +08:00
|
|
|
global.GVA_LOG.Info("定时任务已开启", zap.Any("定时任务状态:", WxTask.IsRunning()))
|
2024-03-29 02:32:26 +08:00
|
|
|
global.GVA_LOG.Info("定时任务已开启", zap.Any("任务数量:", WxTask.Len()))
|
2024-03-21 21:08:45 +08:00
|
|
|
}
|