12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package crontask
- import (
- "context"
- "wechat-api/internal/svc"
- "github.com/robfig/cron/v3"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type CronTask struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewCronTask(ctx context.Context, svcCtx *svc.ServiceContext) *CronTask {
- return &CronTask{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
- func ScheduleRun(c *cron.Cron, serverCtx *svc.ServiceContext) {
- l := NewCronTask(context.Background(), serverCtx)
- c.AddFunc("* * * * *", func() {
- l.sendMsg()
- })
- sendWx := NewCronTask(context.Background(), serverCtx)
- c.AddFunc("* * * * *", func() {
- sendWx.sendWx()
- })
- sendWxOnTimeout := NewCronTask(context.Background(), serverCtx)
- c.AddFunc("* * * * *", func() {
- sendWxOnTimeout.sendWxOnTimeout()
- })
- computeStatistic := NewCronTask(context.Background(), serverCtx)
- c.AddFunc("0 * * * *", func() {
- computeStatistic.computeStatistic()
- })
- contactForm := NewCronTask(context.Background(), serverCtx)
- c.AddFunc("10 0 * * *", func() {
- contactForm.analyze(nil)
- })
- contactForm2 := NewCronTask(context.Background(), serverCtx)
- c.AddFunc("0 8 * * *", func() {
- bot_wxid1 := "wxid_mqq8zf6kdofj22"
- contactForm2.analyze(&bot_wxid1)
- bot_wxid2 := "wxid_4p6046tox6pd22"
- contactForm2.analyze(&bot_wxid2)
- bot_wxid3 := "wxid_s1bes9nbk37v12"
- contactForm2.analyze(&bot_wxid3)
- })
- contactForm3 := NewCronTask(context.Background(), serverCtx)
- c.AddFunc("30 11 * * *", func() {
- bot_wxid1 := "wxid_mqq8zf6kdofj22"
- contactForm3.analyze(&bot_wxid1)
- bot_wxid2 := "wxid_4p6046tox6pd22"
- contactForm3.analyze(&bot_wxid2)
- bot_wxid3 := "wxid_s1bes9nbk37v12"
- contactForm3.analyze(&bot_wxid3)
- })
- contactForm4 := NewCronTask(context.Background(), serverCtx)
- c.AddFunc("0 17 * * *", func() {
- bot_wxid1 := "wxid_mqq8zf6kdofj22"
- contactForm4.analyze(&bot_wxid1)
- bot_wxid2 := "wxid_4p6046tox6pd22"
- contactForm4.analyze(&bot_wxid2)
- bot_wxid3 := "wxid_s1bes9nbk37v12"
- contactForm4.analyze(&bot_wxid3)
- })
- l = NewCronTask(context.Background(), serverCtx)
- c.AddFunc("*/30 * * * *", func() {
- l.wxAddFriend()
- })
- //l = NewCronTask(context.Background(), serverCtx)
- //c.AddFunc("* * * * *", func() {
- // MaxWorker := 10
- // MaxChannel := 3
- // l.compApiCallback(MaxWorker, MaxChannel)
- //})
- }
|