引入ants(正式服已go get)携程池 已支持多店铺批量操作
This commit is contained in:
@@ -2,8 +2,11 @@ package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/panjf2000/ants"
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
@@ -142,11 +145,43 @@ func (c *SyncController) CompareStoreWithOperator() {
|
||||
return retVal, "", err
|
||||
}
|
||||
globals.SugarLogger.Debug(params.StoreIDs, params.VendorIDs)
|
||||
err = cms.GetVendorStoreSkusToStruct(params.Ctx, storeIDs[0], vendorIDs[0])
|
||||
p, _ := ants.NewPoolWithFunc(10, func(data interface{}) {
|
||||
task := data.(*CompareTask)
|
||||
task.Do()
|
||||
})
|
||||
defer p.Release()
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(storeIDs))
|
||||
tasks := make([]*CompareTask, 0, len(storeIDs))
|
||||
for i := 0; i < len(storeIDs); i++ {
|
||||
task := &CompareTask{
|
||||
StoreId: storeIDs[i],
|
||||
VendorId: vendorIDs[0],
|
||||
Ctx: params.Ctx,
|
||||
Wg: &wg,
|
||||
}
|
||||
|
||||
tasks = append(tasks, task)
|
||||
p.Invoke(task)
|
||||
}
|
||||
wg.Wait()
|
||||
// err = cms.GetVendorStoreSkusToStruct(params.Ctx, storeIDs[0], vendorIDs[0])
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
type CompareTask struct {
|
||||
StoreId int
|
||||
VendorId int
|
||||
Ctx *jxcontext.Context
|
||||
Wg *sync.WaitGroup
|
||||
}
|
||||
|
||||
func (t *CompareTask) Do() {
|
||||
cms.GetVendorStoreSkusToStruct(t.Ctx, t.StoreId, t.VendorId)
|
||||
t.Wg.Done()
|
||||
}
|
||||
|
||||
// @Title 删除门店平台商品信息(包括分类)
|
||||
// @Description 删除门店平台商品信息(包括分类)(!!!此操作会先清除平台上已有的商品及分类信息),此操作只适用于单门店模式平台
|
||||
// @Param token header string true "认证token"
|
||||
|
||||
Reference in New Issue
Block a user