Skip to content

Commit

Permalink
分页获取基金列表时可能code为0但是无数据的情况,多次重试可正确获取
Browse files Browse the repository at this point in the history
  • Loading branch information
axiaoxin committed Jul 15, 2021
1 parent ec9df74 commit b22382b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (s Searcher) SearchFunds(ctx context.Context, fundCodes []string) (map[stri
retry.OnRetry(func(n uint, err error) {
logging.Errorf(ctx, "retry#%d: code:%v %v", n, code, err)
}),
retry.Attempts(5),
retry.Attempts(3),
retry.Delay(500*time.Millisecond),
)
if err != nil {
Expand Down
21 changes: 18 additions & 3 deletions datacenter/eastmoney/fund_net_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"time"

"github.com/avast/retry-go"
"github.com/axiaoxin-com/goutils"
"github.com/axiaoxin-com/logging"
"github.com/spf13/viper"
Expand Down Expand Up @@ -129,8 +130,19 @@ func (e EastMoney) QueryAllFundList(ctx context.Context, fundType FundType) (Fun
wg.Done()
}()
index := <-reqChan

resp, err := e.QueryFundListByPage(ctx, fundType, index)
resp := RespFundList{}
err := retry.Do(
func() error {
var err error
resp, err = e.QueryFundListByPage(ctx, fundType, index)
return err
},
retry.OnRetry(func(n uint, err error) {
logging.Errorf(ctx, "retry#%d: page:%v %v", n, index, err)
}),
retry.Attempts(10),
retry.Delay(100*time.Millisecond),
)
if err != nil {
logging.Errorf(ctx, "QueryAllFundList QueryFundListByPage:%d err:%v", index, err)
return
Expand Down Expand Up @@ -190,7 +202,10 @@ func (e EastMoney) QueryFundListByPage(ctx context.Context, fundType FundType, p
return resp, err
}
if resp.ErrCode != 0 {
return resp, fmt.Errorf("QueryFundListByPage error %v", resp.ErrMsg)
return resp, fmt.Errorf("QueryFundListByPage ErrCode != 0: %+v", resp)
}
if resp.ErrCode == 0 && len(resp.Datas) == 0 {
return resp, fmt.Errorf("QueryFundListByPage ErrCode == 0 but not data: %+v", resp)
}
return resp, nil
}

0 comments on commit b22382b

Please sign in to comment.