|
- 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.ZhiosOrderTrackUpdateForTbConsumeFunName] = ZhiosOrderTrackUpdateForTbConsume //淘宝-更新订单
- //jobs[consumeMd.ZhiosOrderTrackCreateForTbConsumeFunName] = ZhiosOrderTrackCreateForTbConsume //淘宝-创建订单
- //jobs[consumeMd.ZhiosOrderTrackRefundForTbAllConsumeFunName] = ZhiosOrderTrackRefundForTbAllConsume //淘宝-全部退款
- //jobs[consumeMd.ZhiosOrderTrackRefundForTbPartConsumeFunName] = ZhiosOrderTrackRefundForTbPartConsume //淘宝-部分退款
-
- jobs[consumeMd.ZhiosOrderTrackCreateForJdConsumeFunName] = ZhiosOrderTrackCreateForJdConsume //京东-创建订单
- jobs[consumeMd.ZhiosOrderTrackUpdateForJdConsumeFunName] = ZhiosOrderTrackUpdateForJdConsume //京东-更新订单
- jobs[consumeMd.ZhiosOrderTrackCreateForPddConsumeFunName] = ZhiosOrderTrackCreateForPddConsume //拼多多-全部订单
- jobs[consumeMd.ZhiosOrderTrackCreateForTikTokTeamConsumeFunName] = ZhiosOrderTrackCreateForTikTokTeamConsume //抖音团长服务费-全部订单
- jobs[consumeMd.ZhiosOrderTrackCreateForWphConsumeFunName] = ZhiosOrderTrackCreateForWphConsume //唯品会-全部订单
- jobs[consumeMd.ZhiosOrderTrackCreateForPddZeroConsumeFunName] = ZhiosOrderTrackCreateForPddZeroConsume //拼多多-全部订单
-
- }
-
- 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(),
- )
- }
- }
|