From c607fa931c81d64aa96d5b1f9cb8956aec3ade1d Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 08:56:02 +0800 Subject: [PATCH] + JdPageAPI --- business/netspider/netspider.go | 2 +- business/partner/purchase/jd/net_spider.go | 5 +++-- globals/api/api.go | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/business/netspider/netspider.go b/business/netspider/netspider.go index 796800164..1fa9d1f7e 100644 --- a/business/netspider/netspider.go +++ b/business/netspider/netspider.go @@ -53,7 +53,7 @@ func getStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask, if handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformNetSpiderHandler); handler != nil { mainStoreIDList, _ := handler.GetStoreIDListByCoordinates(ctx, coordList[0]) if len(mainStoreIDList) > 0 { - task1 := tasksch.NewParallelTask(fmt.Sprintf("GetStoreListByCoordinate[%s] get list", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, + task1 := tasksch.NewParallelTask(fmt.Sprintf("GetStoreListByCoordinate[%s] get list", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(true).SetParallelCount(1), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { pos := batchItemList[0].(*ditu.Coordinate) storeIDList, err := handler.GetStoreIDListByCoordinates(ctx, pos) diff --git a/business/partner/purchase/jd/net_spider.go b/business/partner/purchase/jd/net_spider.go index 924ff64e0..f9e566a26 100644 --- a/business/partner/purchase/jd/net_spider.go +++ b/business/partner/purchase/jd/net_spider.go @@ -12,8 +12,9 @@ import ( ) func (c *PurchaseHandler) GetStoreIDListByCoordinates(ctx *jxcontext.Context, coord *ditu.Coordinate) (storeIDList []string, err error) { - shopListInfo, err := api.JdAPI.GetStoreList(fmt.Sprintf("%.6f", coord.Lng), fmt.Sprintf("%.6f", coord.Lat)) + shopListInfo, err := api.JdPageAPI.GetStoreList(fmt.Sprintf("%.6f", coord.Lng), fmt.Sprintf("%.6f", coord.Lat)) if err != nil { + // time.Sleep(5 * time.Second) return nil, err } if shopListInfo != nil { @@ -27,7 +28,7 @@ func (c *PurchaseHandler) GetStoreIDListByCoordinates(ctx *jxcontext.Context, co } func (c *PurchaseHandler) GetStorePageInfo(ctx *jxcontext.Context, cityInfo, storeID string) (storePageInfo *model.PageShop, err error) { - shopInfo, err2 := api.JdAPI.GetStoreInfo2(storeID) + shopInfo, err2 := api.JdPageAPI.GetStoreInfo2(storeID) if err = err2; err == nil && shopInfo != nil { var lng, lat float64 districtCode := 0 diff --git a/globals/api/api.go b/globals/api/api.go index b4a8d3d2f..dd14840a1 100644 --- a/globals/api/api.go +++ b/globals/api/api.go @@ -28,6 +28,7 @@ import ( var ( JdAPI *jdapi.API + JdPageAPI *jdapi.API ElmAPI *elmapi.API EbaiAPI *ebaiapi.API MtpsAPI *mtpsapi.API @@ -67,6 +68,10 @@ func Init() { cookieValue := beego.AppConfig.DefaultString("jdStorePageCookie", "") JdAPI.SetCookie("shop.o2o.jd.com1", cookieValue) JdAPI.SetCookie("lsp-store1.jddj.com", cookieValue) + + conf := platformapi.NewDefAPIConfig() + conf.MaxSleepSecondWhenExceedLimit = 60 * 30 // 最大重试间隙30分钟 + JdPageAPI = jdapi.NewPageOnly(cookieValue, conf) } else { JdAPI = nil }