- RefreshAllStoresID

- RefreshAllSkusID
- use new tasksch when possible(not use run directly).
This commit is contained in:
gazebo
2018-10-23 16:34:42 +08:00
parent ad3d548824
commit 93a7202423
18 changed files with 323 additions and 155 deletions

View File

@@ -259,9 +259,9 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync bool, params
}
dao.Commit(db)
rootTask := tasksch.RunManagedSeqTask("CreateJdPromotion", userName, func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
rootTask := tasksch.NewSeqTask("CreateJdPromotion", userName, func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
if step == 0 {
task1 := tasksch.RunParallelTask("CreateJdPromotion update sku price", nil, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
task1 := tasksch.NewParallelTask("CreateJdPromotion update sku price", nil, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeID := batchItemList[0].(int)
modifyPricesList := jxutils.SplitSlice(modifyPricesList[storeID], jdapi.MaxStoreSkuBatchSize)
for _, modifyPrices := range modifyPricesList {
@@ -275,7 +275,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync bool, params
}
return nil, nil
}, jxStoreIDs)
task.AddChild(task1)
task.AddChild(task1).Run()
if _, err = task1.GetResult(0); err != nil {
return "", err
}
@@ -284,7 +284,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync bool, params
return "", err
}
} else if step == 2 {
task2 := tasksch.RunParallelTask("CreateJdPromotion CreatePromotionSku", tasksch.NewParallelConfig().SetBatchSize(jdapi.MaxPromotionSkuCount), userName, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
task2 := tasksch.NewParallelTask("CreateJdPromotion CreatePromotionSku", tasksch.NewParallelConfig().SetBatchSize(jdapi.MaxPromotionSkuCount), userName, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
skus := make([]map[string]interface{}, len(batchItemList))
for k, v := range batchItemList {
skus[k] = v.(map[string]interface{})
@@ -292,7 +292,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync bool, params
_, err = promotionHandler.CreatePromotionSku(infoId, "", skus)
return nil, err
}, promotionPrices)
task.AddChild(task2)
task.AddChild(task2).Run()
if _, err = task2.GetResult(0); err != nil {
return "", err
}
@@ -301,6 +301,8 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync bool, params
}
return nil, err
}, 4)
ctx.SetTaskOrAddChild(rootTask)
tasksch.ManageTask(rootTask).Run()
if !isAsync {
_, err = rootTask.GetResult(0)
}
@@ -310,7 +312,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync bool, params
func CreatePromotionByExcel(ctx *jxcontext.Context, isAsync bool, promotionType int, fileHeader *multipart.FileHeader, userName string) (hint string, err error) {
file, err := fileHeader.Open()
if err != nil {
return hint, err
return "", err
}
contents := excel.Excel2Slice(file)
file.Close()
@@ -321,10 +323,10 @@ func CreatePromotionByExcel(ctx *jxcontext.Context, isAsync bool, promotionType
Type: promotionType,
}
if promotionParams.BeginAt, err = excelStr2Time(v[1][colBeginAtIndex]); err != nil {
return hint, err
return "", err
}
if promotionParams.EndAt, err = excelStr2Time(v[1][colEndAtIndex]); err != nil {
return hint, err
return "", err
}
for rowIndex, row := range v {