Skip to content

Instantly share code, notes, and snippets.

@moonsub-kim
Last active March 25, 2022 11:17
Show Gist options
  • Save moonsub-kim/65fdcf80b696f7d63ec7db02d99f0702 to your computer and use it in GitHub Desktop.
Save moonsub-kim/65fdcf80b696f7d63ec7db02d99f0702 to your computer and use it in GitHub Desktop.
dynamodb_retry.go
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