@@ -8,22 +8,22 @@ import (
8
8
"github.com/acoshift/pgsql"
9
9
)
10
10
11
- // BackoffConfig contains common configuration for all backoff strategies
12
- type BackoffConfig struct {
11
+ // Config contains common configuration for all backoff strategies
12
+ type Config struct {
13
13
BaseDelay time.Duration // Base delay for backoff
14
14
MaxDelay time.Duration // Maximum delay cap
15
15
}
16
16
17
- // ExponentialBackoffConfig contains configuration for exponential backoff
18
- type ExponentialBackoffConfig struct {
19
- BackoffConfig
17
+ // ExponentialConfig contains configuration for exponential backoff
18
+ type ExponentialConfig struct {
19
+ Config
20
20
Multiplier float64 // Multiplier for exponential growth
21
21
JitterType JitterType
22
22
}
23
23
24
- // LinearBackoffConfig contains configuration for linear backoff
25
- type LinearBackoffConfig struct {
26
- BackoffConfig
24
+ // LinearConfig contains configuration for linear backoff
25
+ type LinearConfig struct {
26
+ Config
27
27
Increment time.Duration // Amount to increase delay each attempt
28
28
}
29
29
@@ -39,8 +39,8 @@ const (
39
39
EqualJitter
40
40
)
41
41
42
- // NewExponentialBackoff creates a new exponential backoff function
43
- func NewExponentialBackoff (config ExponentialBackoffConfig ) pgsql.BackoffDelayFunc {
42
+ // NewExponential creates a new exponential backoff function
43
+ func NewExponential (config ExponentialConfig ) pgsql.BackoffDelayFunc {
44
44
return func (attempt int ) time.Duration {
45
45
baseDelay := time .Duration (float64 (config .BaseDelay ) * math .Pow (config .Multiplier , float64 (attempt )))
46
46
if baseDelay > config .MaxDelay {
@@ -72,8 +72,8 @@ func NewExponentialBackoff(config ExponentialBackoffConfig) pgsql.BackoffDelayFu
72
72
}
73
73
}
74
74
75
- // NewLinearBackoff creates a new linear backoff function
76
- func NewLinearBackoff (config LinearBackoffConfig ) pgsql.BackoffDelayFunc {
75
+ // NewLinear creates a new linear backoff function
76
+ func NewLinear (config LinearConfig ) pgsql.BackoffDelayFunc {
77
77
return func (attempt int ) time.Duration {
78
78
delay := config .BaseDelay + time .Duration (attempt )* config .Increment
79
79
if delay > config .MaxDelay {
@@ -83,9 +83,9 @@ func NewLinearBackoff(config LinearBackoffConfig) pgsql.BackoffDelayFunc {
83
83
}
84
84
}
85
85
86
- func DefaultExponentialBackoff () pgsql.BackoffDelayFunc {
87
- return NewExponentialBackoff ( ExponentialBackoffConfig {
88
- BackoffConfig : BackoffConfig {
86
+ func DefaultExponential () pgsql.BackoffDelayFunc {
87
+ return NewExponential ( ExponentialConfig {
88
+ Config : Config {
89
89
BaseDelay : 100 * time .Millisecond ,
90
90
MaxDelay : 5 * time .Second ,
91
91
},
@@ -94,9 +94,9 @@ func DefaultExponentialBackoff() pgsql.BackoffDelayFunc {
94
94
})
95
95
}
96
96
97
- func DefaultExponentialBackoffWithFullJitter () pgsql.BackoffDelayFunc {
98
- return NewExponentialBackoff ( ExponentialBackoffConfig {
99
- BackoffConfig : BackoffConfig {
97
+ func DefaultExponentialWithFullJitter () pgsql.BackoffDelayFunc {
98
+ return NewExponential ( ExponentialConfig {
99
+ Config : Config {
100
100
BaseDelay : 100 * time .Millisecond ,
101
101
MaxDelay : 5 * time .Second ,
102
102
},
@@ -105,9 +105,9 @@ func DefaultExponentialBackoffWithFullJitter() pgsql.BackoffDelayFunc {
105
105
})
106
106
}
107
107
108
- func DefaultExponentialBackoffWithEqualJitter () pgsql.BackoffDelayFunc {
109
- return NewExponentialBackoff ( ExponentialBackoffConfig {
110
- BackoffConfig : BackoffConfig {
108
+ func DefaultExponentialWithEqualJitter () pgsql.BackoffDelayFunc {
109
+ return NewExponential ( ExponentialConfig {
110
+ Config : Config {
111
111
BaseDelay : 100 * time .Millisecond ,
112
112
MaxDelay : 5 * time .Second ,
113
113
},
@@ -116,9 +116,9 @@ func DefaultExponentialBackoffWithEqualJitter() pgsql.BackoffDelayFunc {
116
116
})
117
117
}
118
118
119
- func DefaultLinearBackoff () pgsql.BackoffDelayFunc {
120
- return NewLinearBackoff ( LinearBackoffConfig {
121
- BackoffConfig : BackoffConfig {
119
+ func DefaultLinear () pgsql.BackoffDelayFunc {
120
+ return NewLinear ( LinearConfig {
121
+ Config : Config {
122
122
BaseDelay : 100 * time .Millisecond ,
123
123
MaxDelay : 5 * time .Second ,
124
124
},
0 commit comments