阿里云API 错误重试

This commit is contained in:
屈轩
2018-12-22 10:59:06 +08:00
parent 714ab83e87
commit f450c82449
+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)