Automatic merge from release/2.3.0 -> release/2.4.0

* commit '73e753beb76aba7ea7374f8c344c6a5b270bf3ea':
  优化腾讯云请求失败重试
This commit is contained in:
邱剑
2018-11-15 11:13:56 +08:00
+22 -6
View File
@@ -3,6 +3,7 @@ package qcloud
import (
"fmt"
"strings"
"time"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http"
@@ -54,9 +55,9 @@ func jsonRequest(client *common.Client, apiName string, params map[string]string
func vpcRequest(client *common.Client, apiName string, params map[string]string) (jsonutils.JSONObject, error) {
domain := "vpc.tencentcloudapi.com"
// if region, ok := params["Region"]; ok && strings.HasSuffix(region, "-fsi") {
// domain = "vpc." + region + ".tencentcloudapi.com"
// }
if region, ok := params["Region"]; ok && strings.HasSuffix(region, "-fsi") {
domain = "vpc." + region + ".tencentcloudapi.com"
}
return _jsonRequest(client, domain, QCLOUD_API_VERSION, apiName, params)
}
@@ -89,9 +90,24 @@ func _jsonRequest(client *common.Client, domain string, version string, apiName
resp := &QcloudResponse{
BaseResponse: &tchttp.BaseResponse{},
}
err := client.Send(req, resp)
if err != nil {
log.Errorf("request url: %s\nparams: %s\nerror: %v", req.GetDomain(), jsonutils.Marshal(req.GetParams()).PrettyString(), err)
for i := 1; i <= 3; i++ {
err := client.Send(req, resp)
if err == nil {
break
}
needRetry := false
for _, msg := range []string{"EOF", "TLS handshake timeout", "Code=InternalError"} {
if strings.Index(err.Error(), msg) > 0 {
needRetry = true
break
}
}
if needRetry && i != 3 {
log.Errorf("request url %s\nparams: %s\nerror: %v\nafter %d second try again", req.GetDomain(), jsonutils.Marshal(req.GetParams()).PrettyString(), err, i*10)
time.Sleep(time.Second * time.Duration(i*10))
continue
}
log.Errorf("request url: %s\nparams: %s\nresponse: %s\nerror: %v", req.GetDomain(), jsonutils.Marshal(req.GetParams()).PrettyString(), resp.Response, err)
return nil, err
}
return jsonutils.Marshal(resp.Response), nil