init.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package crontask
  2. import (
  3. "context"
  4. "wechat-api/internal/svc"
  5. "github.com/robfig/cron/v3"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. )
  8. type CronTask struct {
  9. logx.Logger
  10. ctx context.Context
  11. svcCtx *svc.ServiceContext
  12. }
  13. func NewCronTask(ctx context.Context, svcCtx *svc.ServiceContext) *CronTask {
  14. return &CronTask{
  15. Logger: logx.WithContext(ctx),
  16. ctx: ctx,
  17. svcCtx: svcCtx,
  18. }
  19. }
  20. func ScheduleRun(c *cron.Cron, serverCtx *svc.ServiceContext) {
  21. //除了fe环境任务关闭 其他环境任务要正常打开
  22. l := NewCronTask(context.Background(), serverCtx)
  23. c.AddFunc("* * * * *", func() {
  24. l.sendMsg()
  25. })
  26. sendWx := NewCronTask(context.Background(), serverCtx)
  27. c.AddFunc("* * * * *", func() {
  28. sendWx.sendWx()
  29. })
  30. sendWxOnTimeout := NewCronTask(context.Background(), serverCtx)
  31. c.AddFunc("* * * * *", func() {
  32. sendWxOnTimeout.sendWxOnTimeout()
  33. })
  34. computeStatistic := NewCronTask(context.Background(), serverCtx)
  35. c.AddFunc("0 * * * *", func() {
  36. computeStatistic.computeStatistic()
  37. })
  38. contactForm := NewCronTask(context.Background(), serverCtx)
  39. c.AddFunc("10 0 * * *", func() {
  40. contactForm.analyze()
  41. })
  42. l = NewCronTask(context.Background(), serverCtx)
  43. c.AddFunc("*/30 * * * *", func() {
  44. l.wxAddFriend()
  45. })
  46. //l = NewCronTask(context.Background(), serverCtx)
  47. //c.AddFunc("* * * * *", func() {
  48. // MaxWorker := 10
  49. // MaxChannel := 3
  50. // l.compApiCallback(MaxWorker, MaxChannel)
  51. //})
  52. }