- 京东门店商品信息同步,部分失败后尝试单个同步
This commit is contained in:
@@ -33,16 +33,17 @@ func (p *PurchaseHandler) syncStoreSkus(ctx *jxcontext.Context, parentTask tasks
|
||||
return "", err
|
||||
}
|
||||
batchSize := jdapi.MaxStoreSkuBatchSize
|
||||
storeSkusLen := len(storeSkus)
|
||||
if storeSkusLen < jdapi.MaxStoreSkuBatchSize*2 {
|
||||
batchSize = (storeSkusLen + 2) / 3
|
||||
} else if storeSkusLen < jdapi.MaxStoreSkuBatchSize {
|
||||
batchSize = (storeSkusLen + 1) / 2
|
||||
} else if storeSkusLen < jdapi.MaxStoreSkuBatchSize/2 {
|
||||
batchSize = 1
|
||||
}
|
||||
// storeSkusLen := len(storeSkus)
|
||||
// if storeSkusLen < jdapi.MaxStoreSkuBatchSize/2 {
|
||||
// batchSize = 1
|
||||
// } else if storeSkusLen < jdapi.MaxStoreSkuBatchSize {
|
||||
// batchSize = (storeSkusLen + 1) / 2
|
||||
// } else if storeSkusLen < jdapi.MaxStoreSkuBatchSize*2 {
|
||||
// batchSize = (storeSkusLen + 2) / 3
|
||||
// }
|
||||
task := tasksch.NewParallelTask("syncStoreSkus京东", tasksch.NewParallelConfig().SetBatchSize(batchSize).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
doWork := func(batchItemList []interface{}) (err error) {
|
||||
var skuPriceInfoList []*jdapi.SkuPriceInfo
|
||||
var skuVendibilityList []*jdapi.StockVendibility
|
||||
var skuStockList []*jdapi.SkuStock
|
||||
@@ -126,7 +127,7 @@ func (p *PurchaseHandler) syncStoreSkus(ctx *jxcontext.Context, parentTask tasks
|
||||
syncMask = -1
|
||||
}
|
||||
if syncMask != 0 && len(batchBindIDs) > 0 {
|
||||
db := dao.GetDB() // 多线程问题
|
||||
// db := dao.GetDB() // 多线程问题
|
||||
sql := `
|
||||
UPDATE store_sku_bind t1
|
||||
SET t1.jd_sync_status = t1.jd_sync_status & ?
|
||||
@@ -140,6 +141,14 @@ func (p *PurchaseHandler) syncStoreSkus(ctx *jxcontext.Context, parentTask tasks
|
||||
} else if len(errList) > 1 {
|
||||
err = fmt.Errorf("%v", errList)
|
||||
}
|
||||
return err
|
||||
}
|
||||
err = doWork(batchItemList)
|
||||
if isErrPartialFailed(err) && len(batchItemList) > 1 {
|
||||
for _, v := range batchItemList {
|
||||
doWork([]interface{}{v})
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}, storeSkus)
|
||||
tasksch.HandleTask(task, parentTask, false).Run()
|
||||
@@ -149,6 +158,13 @@ func (p *PurchaseHandler) syncStoreSkus(ctx *jxcontext.Context, parentTask tasks
|
||||
return task.ID, err
|
||||
}
|
||||
|
||||
func isErrPartialFailed(err error) bool {
|
||||
if errExt, ok := err.(*utils.ErrorWithCode); ok && errExt.Code() == jdapi.ResponseInnerCodePartialFailed {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
globals.SugarLogger.Debugf("jd SyncStoresSkus, storeID:%d, skuIDs:%v", storeID, skuIDs)
|
||||
db := dao.GetDB()
|
||||
|
||||
Reference in New Issue
Block a user