🐛 fix bug
This commit is contained in:
parent
8ae5919c6c
commit
6178edc9d0
@ -4,6 +4,8 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
swaggerFiles "github.com/swaggo/files"
|
swaggerFiles "github.com/swaggo/files"
|
||||||
ginSwagger "github.com/swaggo/gin-swagger"
|
ginSwagger "github.com/swaggo/gin-swagger"
|
||||||
|
r "miniapp/model/common/response"
|
||||||
|
"miniapp/task"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"miniapp/global"
|
"miniapp/global"
|
||||||
@ -44,6 +46,19 @@ func Routers() *gin.Engine {
|
|||||||
PublicGroup.GET("/health", func(c *gin.Context) {
|
PublicGroup.GET("/health", func(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, "ok")
|
c.JSON(http.StatusOK, "ok")
|
||||||
})
|
})
|
||||||
|
PublicGroup.GET("/task/msg", func(c *gin.Context) {
|
||||||
|
tag, _ := task.WxTask.FindJobsByTag("msg")
|
||||||
|
r.OkWithData(tag[0].NextRun(), c)
|
||||||
|
})
|
||||||
|
PublicGroup.GET("/task/jobs", func(c *gin.Context) {
|
||||||
|
jobs := task.WxTask.Jobs()
|
||||||
|
r.OkWithData(len(jobs), c)
|
||||||
|
})
|
||||||
|
PublicGroup.GET("/task/send", func(c *gin.Context) {
|
||||||
|
tag, _ := task.WxTask.FindJobsByTag("sendMsg")
|
||||||
|
r.OkWithData(tag[0].NextRun(), c)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
systemRouter.InitBaseRouter(PublicGroup) // 注册基础功能路由 不做鉴权
|
systemRouter.InitBaseRouter(PublicGroup) // 注册基础功能路由 不做鉴权
|
||||||
|
15
task/task.go
15
task/task.go
@ -13,15 +13,24 @@ func InitTask() {
|
|||||||
WxTask = gocron.NewScheduler(time.Local)
|
WxTask = gocron.NewScheduler(time.Local)
|
||||||
|
|
||||||
// 每天凌晨1点执行
|
// 每天凌晨1点执行
|
||||||
_, err := WxTask.Every(1).Day().At("01:00").Do(CheckUserSurgeryDate) // 检查用户是否已到手术日期
|
//cjob, err := WxTask.Cron("0 1 * * *").Do(CheckUserSurgeryDate) // 检查用户是否已到手术日期
|
||||||
|
cjob, err := WxTask.Every(1).Day().At("04:00").Do(CheckUserSurgeryDate) // 检查用户是否已到手术日期
|
||||||
if err != nil {
|
if err != nil {
|
||||||
global.GVA_LOG.Error("检查用户是否已到手术日期定时任务创建失败", zap.Error(err))
|
global.GVA_LOG.Error("检查用户是否已到手术日期定时任务创建失败", zap.Error(err))
|
||||||
}
|
}
|
||||||
_, err = WxTask.Every(1).Day().At("01:00").Do(SendMsg2User)
|
sjob, err := WxTask.Every(1).Day().At("04:00").Do(SendMsg2User)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
global.GVA_LOG.Error("发送消息定时任务创建失败", zap.Error(err))
|
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()
|
WxTask.StartAsync()
|
||||||
global.GVA_LOG.Info("定时任务已开启", zap.Any("定时任务状态:", WxTask.IsRunning()))
|
global.GVA_LOG.Info("定时任务已开启", zap.Any("定时任务状态:", WxTask.IsRunning()))
|
||||||
|
@ -52,11 +52,12 @@ func SendMsg2User() {
|
|||||||
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.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.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)))
|
//job, err := WxTask.Every(1).Day().At("23:51").LimitRunsTo(1).Do(MiniappSendMsg, strconv.Itoa(int(user.ID)), strconv.Itoa(int(todo.ID)))
|
||||||
|
job.Tag("sendMsg")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
global.GVA_LOG.Error("定时任务创建失败:%s", zap.Error(err))
|
global.GVA_LOG.Error("定时任务创建失败:%s", zap.Error(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
global.GVA_LOG.Info("定时任务创建成功", zap.Any("job", job.LastRun()))
|
global.GVA_LOG.Info("定时发送消息任务创建成功")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user