Merge pull request #817 in YUNIONIO/onecloud from ~QUXUAN/onecloud:hofix/qx-conflict-resolve-2.4.0 to release/2.4.0

* commit '61a0bbed7c4a03e76633e2df8e47726e515acb37':
  阿里云API 错误重试
This commit is contained in:
邱剑
2018-12-22 11:03:19 +08:00
+7 -2
View File
@@ -50,14 +50,19 @@ func NewAliyunClient(providerId string, providerName string, accessKey string, s
func jsonRequest(client *sdk.Client, domain, apiVersion, apiName string, params map[string]string) (jsonutils.JSONObject, error) {
for i := 1; i < 4; i++ {
resp, err := _jsonRequest(client, domain, apiVersion, 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)