init.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. //l := NewCronTask(context.Background(), serverCtx)
  22. //c.AddFunc("* * * * *", func() {
  23. // l.sendMsg()
  24. //})
  25. //
  26. //sendWx := NewCronTask(context.Background(), serverCtx)
  27. //c.AddFunc("* * * * *", func() {
  28. // sendWx.sendWx()
  29. //})
  30. //
  31. //sendWxOnTimeout := NewCronTask(context.Background(), serverCtx)
  32. //c.AddFunc("* * * * *", func() {
  33. // sendWxOnTimeout.sendWxOnTimeout()
  34. //})
  35. //
  36. //computeStatistic := NewCronTask(context.Background(), serverCtx)
  37. //c.AddFunc("0 * * * *", func() {
  38. // computeStatistic.computeStatistic()
  39. //})
  40. //syncWx := NewCronTask(context.Background(), serverCtx)
  41. //c.AddFunc("*/30 * * * *", func() {
  42. // syncWx.syncWx()
  43. //})
  44. contactForm := NewCronTask(context.Background(), serverCtx)
  45. c.AddFunc("@every 1m", func() {
  46. contactForm.analyze()
  47. })
  48. //l = NewCronTask(context.Background(), serverCtx)
  49. //c.AddFunc("* * * * *", func() {
  50. // MaxWorker := 10
  51. // MaxChannel := 3
  52. // l.compApiCallback(MaxWorker, MaxChannel)
  53. //})
  54. }