add sort
This commit is contained in:
@@ -59,8 +59,10 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID int64) ([]b
|
||||
return nil, findProductFeatureErr
|
||||
}
|
||||
var featureIDs []int64
|
||||
isImportantMap := make(map[int64]int64, len(productFeatureList))
|
||||
for _, pf := range productFeatureList {
|
||||
featureIDs = append(featureIDs, pf.FeatureId)
|
||||
isImportantMap[pf.FeatureId] = pf.IsImportant
|
||||
}
|
||||
if len(featureIDs) == 0 {
|
||||
return nil, errors.New("featureIDs 是空的")
|
||||
@@ -79,6 +81,7 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID int64) ([]b
|
||||
errorsCh = make(chan error, len(featureList))
|
||||
errorCount int32
|
||||
errorLimit = len(featureList)
|
||||
retryNum = 5
|
||||
)
|
||||
|
||||
for i, feature := range featureList {
|
||||
@@ -95,9 +98,26 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID int64) ([]b
|
||||
ApiID: feature.ApiId,
|
||||
Success: false,
|
||||
}
|
||||
// 请求参数预处理
|
||||
resp, preprocessErr := a.PreprocessRequestApi(params, feature.ApiId)
|
||||
timestamp := time.Now().Format("2006-01-02 15:04:05")
|
||||
var (
|
||||
resp json.RawMessage
|
||||
preprocessErr error
|
||||
)
|
||||
// 若 isImportantMap[feature.ID] == 1,则表示需要在出错时重试
|
||||
isImportant := isImportantMap[feature.Id] == 1
|
||||
tryCount := 0
|
||||
for {
|
||||
tryCount++
|
||||
resp, preprocessErr = a.PreprocessRequestApi(params, feature.ApiId)
|
||||
if preprocessErr == nil {
|
||||
break
|
||||
}
|
||||
if isImportant && tryCount < retryNum {
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if preprocessErr != nil {
|
||||
result.Timestamp = timestamp
|
||||
result.Error = preprocessErr.Error()
|
||||
@@ -123,7 +143,7 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID int64) ([]b
|
||||
close(resultsCh)
|
||||
close(errorsCh)
|
||||
}()
|
||||
// 收集所有结果并合并
|
||||
// 收集所有结果并合并z
|
||||
var responseData []APIResponseData
|
||||
for result := range resultsCh {
|
||||
responseData = append(responseData, result)
|
||||
|
||||
Reference in New Issue
Block a user