增加分组并发请求的逻辑
This commit is contained in:
@ -10,6 +10,7 @@ package mesh
|
||||
import (
|
||||
"context"
|
||||
"git.zhangdeman.cn/zhangdeman/network/httpclient"
|
||||
"git.zhangdeman.cn/zhangdeman/network/httpclient/define"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@ -24,7 +25,7 @@ func Request(req *RequestConfig, receiver any) *Response {
|
||||
ErrorMessage: "",
|
||||
Raw: nil,
|
||||
DataMap: nil,
|
||||
AliasResultTable: make(map[string]*Response),
|
||||
AliasResultTable: make(map[string]*define.Response),
|
||||
Lock: &sync.RWMutex{},
|
||||
},
|
||||
reqCfg: req,
|
||||
@ -67,6 +68,7 @@ func (c *client) doRequest(apiList []*RequestConfigGroupItem) bool {
|
||||
)
|
||||
// 初始化一下请求
|
||||
c.initApiCfg(apiCfg)
|
||||
// TODO: 构造生成请求参数
|
||||
if httpClient, err = httpclient.NewHttpClient(apiCfg.RequestCfg, apiCfg.CacheInstance); nil != err {
|
||||
// 此处获取客户端实例即发生异常, 忽略一切配置, 直接作为全局失败, 后续也不请求了
|
||||
c.resp.ErrorCode = "-500"
|
||||
@ -86,12 +88,23 @@ func (c *client) doRequest(apiList []*RequestConfigGroupItem) bool {
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
// TODO : 判断是否已经是最终失败
|
||||
if c.resp.FinalFailure && !apiCfg.FinalFailureAllow {
|
||||
// 已经最终失败, 并且最终失败后, 当前接口已经不允许请求, 不在进行请求
|
||||
return
|
||||
}
|
||||
resp := httpClientList[clientIdx].Request()
|
||||
c.resp.Lock.Lock()
|
||||
defer c.resp.Lock.Unlock()
|
||||
if !resp.IsSuccess {
|
||||
// 判断是否已经是最终失败
|
||||
if apiCfg.FailBehavior.FinalFailure || apiCfg.FailBehavior.Action == FailBehaviorError {
|
||||
c.resp.FinalFailure = true
|
||||
// 判断是否继续, 只能阻断后续分组请求,无法阻断当前租的请求
|
||||
isContinue = FailBehaviorContinue == apiCfg.FailBehavior.Action
|
||||
}
|
||||
}
|
||||
// 记录请求的信息
|
||||
c.resp.AliasResultTable[apiCfg.Alias] = resp
|
||||
}(idx, apiCfg)
|
||||
}
|
||||
wg.Wait()
|
||||
|
Reference in New Issue
Block a user