Automatic merge from release/2.1.0 -> release/2.2.0

* commit '1b93340eeb5bd6d59430ab5a96ec3dc6f3f551dd':
  阿里云API 错误重试
This commit is contained in:
邱剑
2018-12-22 11:00:25 +08:00
+7 -2
View File
@@ -47,14 +47,19 @@ func NewAliyunClient(providerId string, providerName string, accessKey string, s
func jsonRequest(client *sdk.Client, apiName string, params map[string]string) (jsonutils.JSONObject, error) {
for i := 1; i < 4; i++ {
resp, err := _jsonRequest(client, "ecs.aliyuncs.com", ALIYUN_API_VERSION, apiName, params)
retry := false
if err != nil {
for _, code := range []string{"SignatureNonceUsed", "InvalidInstance.NotSupported"} {
if strings.Contains(err.Error(), code) {
time.Sleep(time.Second * time.Duration(i*10))
continue
retry = true
break
}
}
}
if retry {
time.Sleep(time.Second * time.Duration(i*10))
continue
}
return resp, err
}
return nil, fmt.Errorf("timeout for request %s params: %s", apiName, params)