|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package consume
-
- import (
- "applet/app/utils/logx"
- consumeMd "applet/consume/md"
- "time"
- )
-
- var (
- jobs = map[string]func(consumeMd.MqQueue){}
- )
-
- func Init() {
- // 初始化任务列表
- initConsumes()
- }
-
- // 增加消费任务队列
- func initConsumes() {
- jobs[consumeMd.CanalOrderConsumeFunName] = CanalOrderConsume
- jobs[consumeMd.CanalGuideOrderConsumeFunName] = CanalGuideOrderConsume
- jobs[consumeMd.ZhiOsUserVisitIpAddressConsumeFunName] = ZhiOsUserVisitIpAddressConsume
- jobs[consumeMd.DouShenUserRegisterConsumeForOfficialFunName] = DouShenUserRegisterConsumeForOfficial
- jobs[consumeMd.DouShenUserRegisterConsumeForOperationCenterFunName] = DouShenUserRegisterConsumeForOperationCenter
- jobs[consumeMd.DouShenUserRegisterConsumeForMyRecommenderFunName] = DouShenUserRegisterConsumeForMyRecommender
- jobs[consumeMd.DouShenUserRegisterConsumeForMyFansFunName] = DouShenUserRegisterConsumeForMyFans
- jobs[consumeMd.ZhiosFastReturnOrderPayFunName] = ZhiosFastReturnOrderPay
- jobs[consumeMd.ZhiosFastReturnOrderSuccessFunName] = ZhiosFastReturnOrderSuccess
- jobs[consumeMd.ZhiosFastReturnOrderRefundFunName] = ZhiosFastReturnOrderRefund
- }
-
- func Run() {
- for _, v := range consumeMd.RabbitMqQueueKeyList {
- if _, ok := jobs[v.ConsumeFunName]; ok {
- go doConsume(v.ConsumeFunName, *v)()
- }
- }
- }
-
- func doConsume(fnName string, queue consumeMd.MqQueue) func() {
- return func() {
- begin := time.Now().Local()
- jobs[fnName](queue)
- end := time.Now().Local()
- logx.Infof(
- "[%s] AutoConsume started at <%s>, ended at <%s> duration <%s>",
- fnName,
- begin.Format("2006-01-02 15:04:05.000"),
- end.Format("2006-01-02 15:04:05.000"),
- time.Duration(end.UnixNano()-begin.UnixNano()).String(),
- )
- }
- }
|