🐛 修复任务多次发送bug

This commit is contained in:
loser 2024-03-30 23:51:35 +08:00
parent 6608d8e966
commit 7034bb7b2f
2 changed files with 4 additions and 7 deletions

View File

@ -22,11 +22,7 @@ func InitTask() {
global.GVA_LOG.Error("发送消息定时任务创建失败", zap.Error(err))
}
//_, err = WxTask.Every("1m").Do(MiniappSendMsg, "o9Fq_6_cYKvOWnyUM3McC11hWsTI", "测试", "测试", "测试")
_, err = WxTask.Every("1m").Do(SendMsg2User)
if err != nil {
global.GVA_LOG.Error("检查用户是否已到手术日期定时任务创建失败", zap.Error(err))
}
// 开启定时任务
WxTask.StartAsync()

View File

@ -49,13 +49,14 @@ func SendMsg2User() {
// 根据用户手术信息 发送提醒消息
if user.IsSurgery == 0 && todo.RemindPeriod == 0 && todo.IsFinish == 0 {
// 根据年月日时发送消息
//job, err := WxTask.Every(1).Day().At(todo.RemindTime).Do(MiniappSendMsg, *user.WechatOpenId, todo.Content, todo.RemindPeriod, todo.RemindTime)
job, err := WxTask.Every(1).Day().At(todo.RemindTime).Do(MiniappSendMsg, strconv.Itoa(int(user.ID)), strconv.Itoa(int(todo.ID)))
global.GVA_LOG.Info("定时任务创建成功", zap.Any("job", job))
job, err := WxTask.Every(1).Day().At(todo.RemindTime).LimitRunsTo(1).Do(MiniappSendMsg, strconv.Itoa(int(user.ID)), strconv.Itoa(int(todo.ID)))
//job, err := WxTask.Cron("0 30 23 30 3 2024").Do(MiniappSendMsg, strconv.Itoa(int(user.ID)), strconv.Itoa(int(todo.ID)))
//job, err := WxTask.Every(1).Day().At("23:51").LimitRunsTo(1).Do(MiniappSendMsg, strconv.Itoa(int(user.ID)), strconv.Itoa(int(todo.ID)))
if err != nil {
global.GVA_LOG.Error("定时任务创建失败:%s", zap.Error(err))
return
}
global.GVA_LOG.Info("定时任务创建成功", zap.Any("job", job.LastRun()))
}
}
}