Last active
March 25, 2022 11:17
-
-
Save moonsub-kim/65fdcf80b696f7d63ec7db02d99f0702 to your computer and use it in GitHub Desktop.
dynamodb_retry.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var timeout time.Time = 30 * time.Millisecond | |
var maxRetry int = 3 | |
func queryWithRetry(ctx context.Context, input *dynamodb.QueryInput) (*dynamodb.QueryOutput, error) { | |
for i := 0; i < maxRetry; i++ { | |
res, err := func() (*dynamodb.QueryOutput, error) { | |
timeoutCtx, cancel := context.WithTimeout(ctx, timeout) | |
defer cancel() | |
return dynamoDB.Query(input) | |
}() | |
if isRetryable(err) { | |
continue | |
} else if err != nil { | |
return nil, err | |
} | |
return res, nil | |
} | |
return nil, errors.New("max retry exceeded") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment