优化mesh请求 #4
@ -48,8 +48,7 @@ type RequestConfigGroupItem struct {
|
|||||||
//
|
//
|
||||||
// Date : 15:51 2025/3/28
|
// Date : 15:51 2025/3/28
|
||||||
type RequestConfigGroupItemFailBehavior struct {
|
type RequestConfigGroupItemFailBehavior struct {
|
||||||
Action string `json:"action"` // 请求失败的行为: continue: 继续执行下一个请求, break: 停止执行后续请求
|
Action string `json:"action"` // 请求失败的行为: continue: 继续执行下一个请求, error: 停止执行后续请求, 并且整体请求失败
|
||||||
FinalFailure bool `json:"final_failure"` // 是否作为最终失败: action = break时, 无论外部是什么值, 永远为true, 当 action = continue时, 该值由外部传入, 原因: 当前接口失败, 可能还需要调用一些后续接口做些逻辑.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RequestConfigGroupItemParamRule 参数提取规则
|
// RequestConfigGroupItemParamRule 参数提取规则
|
||||||
|
@ -173,9 +173,12 @@ func (c *client) doRequest(apiList []*RequestConfigGroupItem) bool {
|
|||||||
c.resp.Lock.Lock()
|
c.resp.Lock.Lock()
|
||||||
defer c.resp.Lock.Unlock()
|
defer c.resp.Lock.Unlock()
|
||||||
if !resp.IsSuccess {
|
if !resp.IsSuccess {
|
||||||
|
// 哪些接口请求失败: 注意,接口请求失败不代表整体失败,接口可能针对失败配置规则 continue
|
||||||
|
c.resp.FailApiAlias = append(c.resp.FailApiAlias, apiCfg.Alias)
|
||||||
// 判断是否已经是最终失败
|
// 判断是否已经是最终失败
|
||||||
if apiCfg.FailBehavior.FinalFailure || apiCfg.FailBehavior.Action == FailBehaviorError {
|
if apiCfg.FailBehavior.Action == FailBehaviorError {
|
||||||
c.resp.FinalFailure = true
|
c.resp.FinalFailure = true
|
||||||
|
c.resp.FailureApiAlias = apiCfg.Alias // 导致最终请求失败的接口
|
||||||
// 判断是否继续, 只能阻断后续分组请求,无法阻断当前租的请求
|
// 判断是否继续, 只能阻断后续分组请求,无法阻断当前租的请求
|
||||||
isContinue = FailBehaviorContinue == apiCfg.FailBehavior.Action
|
isContinue = FailBehaviorContinue == apiCfg.FailBehavior.Action
|
||||||
}
|
}
|
||||||
@ -192,13 +195,8 @@ func (c *client) initApiCfg(apiCfg *RequestConfigGroupItem) {
|
|||||||
if apiCfg.FailBehavior == nil {
|
if apiCfg.FailBehavior == nil {
|
||||||
apiCfg.FailBehavior = &RequestConfigGroupItemFailBehavior{
|
apiCfg.FailBehavior = &RequestConfigGroupItemFailBehavior{
|
||||||
Action: FailBehaviorError, // 默认失败终止请求
|
Action: FailBehaviorError, // 默认失败终止请求
|
||||||
FinalFailure: true, // 默认一旦失败,则争个整个失败
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if apiCfg.FailBehavior.Action == FailBehaviorError {
|
|
||||||
// 配置了请求失败则报错, 一定是导致结果最终失败
|
|
||||||
apiCfg.FailBehavior.FinalFailure = true
|
|
||||||
}
|
|
||||||
// 每一个请求有独立的context
|
// 每一个请求有独立的context
|
||||||
apiCfg.RequestCfg.Ctx = context.WithValue(c.reqCfg.Ctx, "alias", apiCfg.Alias)
|
apiCfg.RequestCfg.Ctx = context.WithValue(c.reqCfg.Ctx, "alias", apiCfg.Alias)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user