register.go 633 B

123456789101112131415161718192021
  1. package mqtask
  2. import (
  3. "github.com/hibiken/asynq"
  4. "github.com/suyuan32/simple-admin-job/internal/mqs/amq/handler/amq/wxhook"
  5. "github.com/suyuan32/simple-admin-job/internal/mqs/amq/handler/amq/base"
  6. "github.com/suyuan32/simple-admin-job/internal/mqs/amq/types/pattern"
  7. )
  8. // Register adds task to cron. | 在此处定义任务处理逻辑,注册worker.
  9. func (m *MQTask) Register() {
  10. mux := asynq.NewServeMux()
  11. // define the handler | 定义处理逻辑
  12. mux.Handle(pattern.RecordHelloWorld, base.NewHelloWorldHandler(m.svcCtx))
  13. mux.Handle(pattern.RecordSayMorning, wxhook.NewSayMorningHandler(m.svcCtx))
  14. m.mux = mux
  15. }