From 0bf5c5f7762084bcead7f73b87d4c520c61a675d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=84=86=E9=92=B0?= Date: Sat, 4 Jan 2025 23:20:32 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E7=94=A8=E9=87=8D=E8=AF=95=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E5=BD=93=E8=AF=B7=E6=B1=82=E6=97=A0=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=97=B6=E8=87=AA=E5=8A=A8=E9=87=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alibabacloudstack/connectivity/client.go | 39 ++++++++++++++++++------ 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/alibabacloudstack/connectivity/client.go b/alibabacloudstack/connectivity/client.go index fd44748a..76d3ec84 100644 --- a/alibabacloudstack/connectivity/client.go +++ b/alibabacloudstack/connectivity/client.go @@ -94,7 +94,6 @@ type AlibabacloudStackClient struct { bssopenapiconn *bssopenapi.Client rdsconn *rds.Client ramconn *ram.Client - essconn *ess.Client gpdbconn *gpdb.Client drdsconn *drds.Client elasticsearchconn *elasticsearch.Client @@ -275,16 +274,16 @@ func (client *AlibabacloudStackClient) WithCloudApiClient(do func(*cloudapi.Clie } func (client *AlibabacloudStackClient) WithEssClient(do func(*ess.Client) (interface{}, error)) (interface{}, error) { - if client.essconn == nil { - conn, error := client.WithProductSDKClient(ESSCode) - if error != nil { - return nil, error - } - client.essconn = &ess.Client{ - Client: *conn, - } + conn, err := client.getConnectClient("ESS") + if err != nil { + return nil, err + } + essconn := &ess.Client{ + Client: *conn, } - return do(client.essconn) + return retryDo(func() (interface{}, error) { + return do(essconn) + }) } func (client *AlibabacloudStackClient) WithOnsClient(do func(*ons.Client) (interface{}, error)) (interface{}, error) { @@ -1396,3 +1395,23 @@ func SetResourceData(d *schema.ResourceData, value interface{}, keys ...string) } return nil } + +func retryDo(do func() (interface{}, error)) (interface{}, error) { + var response interface{} + var err error + wait := IncrementalWait(3*time.Second, 3*time.Second) + resource.Retry(5*time.Minute, func() *resource.RetryError { + //仅在请求无正常返回时重试 + response, err = do() + if err == nil { + return nil + } + if response == nil { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + + }) + return response, err +}