-
Notifications
You must be signed in to change notification settings - Fork 1
/
option.go
51 lines (44 loc) · 1.25 KB
/
option.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
package valkyrietry
import (
"time"
)
type Configuration struct {
MaxRetryAttempts uint
InitialRetryDelay time.Duration
RetryBackoffMultiplier float32
JitterPercentage float32
}
// option is a function option used to configure a Valkyrietry.
type Option func(c *Configuration)
// WithMaxRetryAttempts
// Set the maximum number of retry attempts for the retry mechanism.
//
// if you set the attempt to 0, it means it will run until the process succed
func WithMaxRetryAttempts(attempt uint) Option {
return func(c *Configuration) {
c.MaxRetryAttempts = attempt
}
}
// WithRetryDelay
// Set the initial duration value for the first retry.
func WithRetryDelay(delay time.Duration) Option {
return func(c *Configuration) {
c.InitialRetryDelay = delay
}
}
// WithRetryBackoffMultiplier
// Set the multiplier for each failed retry attempt.
// Formula: initial retry delay * multiplier.
func WithRetryBackoffMultiplier(multiplier float32) Option {
return func(c *Configuration) {
c.RetryBackoffMultiplier = multiplier
}
}
// WithJitter
// Set the percentage of jitter value to determine the lowest and highest
// random values.
func WithJitter(percentage float32) Option {
return func(c *Configuration) {
c.JitterPercentage = percentage
}
}