From efea36e7b64d6fc1bfd0c0647d9a3c5fa8e91403 Mon Sep 17 00:00:00 2001 From: tom twinkle Date: Thu, 31 Aug 2023 12:11:18 +0900 Subject: [PATCH] feat: awss3 DownloadFiles use backoff --- aws/awss3/awss3.go | 16 ++++++++++++---- aws/go.mod | 1 + aws/go.sum | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/aws/awss3/awss3.go b/aws/awss3/awss3.go index ccbc8fb..d64f4e5 100644 --- a/aws/awss3/awss3.go +++ b/aws/awss3/awss3.go @@ -15,6 +15,8 @@ import ( "strings" "time" + "github.com/cenkalti/backoff/v4" + "github.com/88labs/go-utils/aws/awss3/options/s3list" "github.com/88labs/go-utils/aws/awss3/options/s3head" @@ -326,10 +328,16 @@ func DownloadFiles(ctx context.Context, region awsconfig.Region, bucketName Buck return nil, err } eg.Go(func() error { - if _, err := downloader.Download(ctx, f, &s3.GetObjectInput{ - Bucket: bucketName.AWSString(), - Key: s3Key.AWSString(), - }); err != nil { + b := backoff.WithContext(backoff.NewExponentialBackOff(), ctx) + if err := backoff.Retry(func() error { + if _, err := downloader.Download(ctx, f, &s3.GetObjectInput{ + Bucket: bucketName.AWSString(), + Key: s3Key.AWSString(), + }); err != nil { + return err + } + return nil + }, b); err != nil { return err } return nil diff --git a/aws/go.mod b/aws/go.mod index 1949029..f644262 100644 --- a/aws/go.mod +++ b/aws/go.mod @@ -39,6 +39,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/sso v1.13.5 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.5 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.21.5 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect diff --git a/aws/go.sum b/aws/go.sum index c66a009..6640ec3 100644 --- a/aws/go.sum +++ b/aws/go.sum @@ -56,6 +56,8 @@ github.com/aws/smithy-go v1.14.2 h1:MJU9hqBGbvWZdApzpvoF2WAIJDbtjK2NDJSiJP7HblQ= github.com/aws/smithy-go v1.14.2/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/bxcodec/faker/v3 v3.8.1 h1:qO/Xq19V6uHt2xujwpaetgKhraGCapqY2CRWGD/SqcM= github.com/bxcodec/faker/v3 v3.8.1/go.mod h1:DdSDccxF5msjFo5aO4vrobRQ8nIApg8kq3QWPEQD6+o= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=