智慧食堂-队列消费项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 2 месеци
пре 2 месеци
пре 2 месеци
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package consume
  2. import (
  3. "applet/app/utils/logx"
  4. consumeMd "applet/consume/md"
  5. "time"
  6. )
  7. var (
  8. jobs = map[string]func(consumeMd.MqQueue){}
  9. )
  10. func Init() {
  11. // 初始化任务列表
  12. initConsumes()
  13. }
  14. // 增加消费任务队列
  15. func initConsumes() {
  16. //////////////////////////////////////// ORDER /////////////////////////////////////////////////////
  17. jobs[consumeMd.JudgePackageOrdStateQueueConsumeFunName] = JudgePackageOrdStateQueueConsume
  18. }
  19. func Run() {
  20. for _, v := range consumeMd.RabbitMqQueueKeyList {
  21. if _, ok := jobs[v.ConsumeFunName]; ok {
  22. go doConsume(v.ConsumeFunName, *v)()
  23. }
  24. }
  25. }
  26. func doConsume(fnName string, queue consumeMd.MqQueue) func() {
  27. return func() {
  28. begin := time.Now().Local()
  29. jobs[fnName](queue)
  30. end := time.Now().Local()
  31. logx.Infof(
  32. "[%s] AutoConsume started at <%s>, ended at <%s> duration <%s>",
  33. fnName,
  34. begin.Format("2006-01-02 15:04:05.000"),
  35. end.Format("2006-01-02 15:04:05.000"),
  36. time.Duration(end.UnixNano()-begin.UnixNano()).String(),
  37. )
  38. }
  39. }