Commit 41a95485 by huangchengyi
parents 59450592 90f06e0a
Showing with 14 additions and 15 deletions
...@@ -45,33 +45,33 @@ func Synchronization(ctx *gin.Context) { ...@@ -45,33 +45,33 @@ func Synchronization(ctx *gin.Context) {
goodsIdArr := php2go.Explode(",", GoodsIdStr) goodsIdArr := php2go.Explode(",", GoodsIdStr)
//wg := sync.WaitGroup{} //协程 //wg := sync.WaitGroup{} //协程
ch := make(chan sync.Map) //管道 ch := make(chan sync.Map) //管道
p := 0; //总共协程 p := 0 //总共协程
zyGoodsId := make([]string, 0) zyGoodsId := make([]string, 0)
lyGoodsId := make([]string, 0) lyGoodsId := make([]string, 0)
for _, goods_id := range goodsIdArr { for _, goodsId := range goodsIdArr {
if goods_id == "" { if goodsId == "" {
continue; continue
} }
if len(goods_id) < 19 { //自营 if len(goodsId) < 19 { //自营
zyGoodsId = append(zyGoodsId, goods_id) zyGoodsId = append(zyGoodsId, goodsId)
if len(zyGoodsId) >= goods_slice_count { if len(zyGoodsId) >= goods_slice_count {
common.PrintDebugHtml(ctx, "zy增加协程1001:") common.PrintDebugHtml(ctx, "zy增加协程1001:")
common.PrintDebugHtml(ctx, zyGoodsId) common.PrintDebugHtml(ctx, zyGoodsId)
//wg.Add(1) //协程计数一 //wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(ctx, zyGoodsId, ch) go zyService.ZyGoodsDetail(ctx, zyGoodsId, ch)
zyGoodsId = zyGoodsId[:0:0] zyGoodsId = zyGoodsId[:0:0]
p ++; p++
} }
} else { //联营 } else { //联营
lyGoodsId = append(lyGoodsId, goods_id) lyGoodsId = append(lyGoodsId, goodsId)
if len(lyGoodsId) >= goods_slice_count { if len(lyGoodsId) >= goods_slice_count {
common.PrintDebugHtml(ctx, "ly增加协程1002:") common.PrintDebugHtml(ctx, "ly增加协程1002:")
common.PrintDebugHtml(ctx, lyGoodsId) common.PrintDebugHtml(ctx, lyGoodsId)
//wg.Add(1) //wg.Add(1)
go lyService.LyGoodsDetail(ctx, lyGoodsId, ch) go lyService.LyGoodsDetail(ctx, lyGoodsId, ch)
lyGoodsId = lyGoodsId[:0:0] lyGoodsId = lyGoodsId[:0:0]
p ++; p++
} }
} }
} }
...@@ -81,7 +81,7 @@ func Synchronization(ctx *gin.Context) { ...@@ -81,7 +81,7 @@ func Synchronization(ctx *gin.Context) {
common.PrintDebugHtml(ctx, zyGoodsId) common.PrintDebugHtml(ctx, zyGoodsId)
//wg.Add(1) //协程计数一 //wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(ctx, zyGoodsId, ch) go zyService.ZyGoodsDetail(ctx, zyGoodsId, ch)
p ++; p++
} }
if len(lyGoodsId) > 0 { if len(lyGoodsId) > 0 {
...@@ -89,7 +89,7 @@ func Synchronization(ctx *gin.Context) { ...@@ -89,7 +89,7 @@ func Synchronization(ctx *gin.Context) {
common.PrintDebugHtml(ctx, zyGoodsId) common.PrintDebugHtml(ctx, zyGoodsId)
//wg.Add(1) //wg.Add(1)
go lyService.LyGoodsDetail(ctx, lyGoodsId, ch) go lyService.LyGoodsDetail(ctx, lyGoodsId, ch)
p ++; p++
} }
//wg.Wait() //wg.Wait()
...@@ -97,22 +97,21 @@ func Synchronization(ctx *gin.Context) { ...@@ -97,22 +97,21 @@ func Synchronization(ctx *gin.Context) {
temp := make(map[string]interface{}) temp := make(map[string]interface{})
for i := 0; i < p; i++ { for i := 0; i < p; i++ {
select { select {
case GoodsRes := <- ch: case GoodsRes := <-ch:
GoodsRes.Range(func(k, v interface{}) bool { GoodsRes.Range(func(k, v interface{}) bool {
s, _ := k.(string) s, _ := k.(string)
temp[s] = v temp[s] = v
return true return true
}) })
case <- time.After(time.Second *6): case <-time.After(time.Second * 6):
logger.Log("协程超时","sku",1) logger.Log("协程超时", "sku", 1)
} }
} }
common.Output(ctx, 0, "success", temp) common.Output(ctx, 0, "success", temp)
} }
/* /*
健康监测 健康监测
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment