-
Notifications
You must be signed in to change notification settings - Fork 50
/
awsv2_retry.go
57 lines (45 loc) · 1.53 KB
/
awsv2_retry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package aws
import (
"math"
"time"
"github.com/aws/aws-sdk-go-v2/aws/retry"
)
func DefaultClientRetryOptions(clientConfig ClientConfigAware) []func(*retry.StandardOptions) {
settings := clientConfig.GetSettings()
options := []func(*retry.StandardOptions){
RetryWithMaxBackoff(settings.Backoff.MaxInterval),
RetryWithMaxAttempts(settings.Backoff.MaxAttempts),
RetryWithBackoff(NewBackoffDelayer(settings.Backoff.InitialInterval, settings.Backoff.MaxInterval)),
RetryWithRateLimiter(NewNopRateLimiter()),
}
options = append(options, clientConfig.GetRetryOptions()...)
return options
}
func RetryWithMaxAttempts(maxAttempts int) func(*retry.StandardOptions) {
return func(options *retry.StandardOptions) {
if maxAttempts <= 0 {
maxAttempts = math.MaxInt
}
options.MaxAttempts = maxAttempts
}
}
func RetryWithMaxBackoff(maxBackoff time.Duration) func(*retry.StandardOptions) {
return func(options *retry.StandardOptions) {
options.MaxBackoff = maxBackoff
}
}
func RetryWithBackoff(backoff retry.BackoffDelayer) func(*retry.StandardOptions) {
return func(options *retry.StandardOptions) {
options.Backoff = backoff
}
}
func RetryWithRateLimiter(rateLimiter retry.RateLimiter) func(options *retry.StandardOptions) {
return func(options *retry.StandardOptions) {
options.RateLimiter = rateLimiter
}
}
func RetryWithRetryables(retryables []retry.IsErrorRetryable) func(options *retry.StandardOptions) {
return func(options *retry.StandardOptions) {
options.Retryables = append(options.Retryables, retryables...)
}
}