init.go 1.5 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. //
  27. //sendWx := NewCronTask(context.Background(), serverCtx)
  28. //c.AddFunc("* * * * *", func() {
  29. // sendWx.sendWx()
  30. //})
  31. //
  32. //sendWxOnTimeout := NewCronTask(context.Background(), serverCtx)
  33. //c.AddFunc("* * * * *", func() {
  34. // sendWxOnTimeout.sendWxOnTimeout()
  35. //})
  36. //
  37. //computeStatistic := NewCronTask(context.Background(), serverCtx)
  38. //c.AddFunc("0 * * * *", func() {
  39. // computeStatistic.computeStatistic()
  40. //})
  41. //
  42. //contactForm := NewCronTask(context.Background(), serverCtx)
  43. //c.AddFunc("10 0 * * *", func() {
  44. // contactForm.analyze()
  45. //})
  46. //
  47. //l = NewCronTask(context.Background(), serverCtx)
  48. //c.AddFunc("*/30 * * * *", func() {
  49. // l.wxAddFriend()
  50. //})
  51. //l = NewCronTask(context.Background(), serverCtx)
  52. //c.AddFunc("* * * * *", func() {
  53. // MaxWorker := 10
  54. // MaxChannel := 3
  55. // l.compApiCallback(MaxWorker, MaxChannel)
  56. //})
  57. }