gapic-common 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/gapic/call_options/retry_policy.rb +2 -1
- data/lib/gapic/common/retry_policy.rb +28 -8
- data/lib/gapic/common/version.rb +1 -1
- data/lib/gapic/operation/retry_policy.rb +4 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e4338a183319704aa9fb613e73d34b4092a94ad56f3136c2d4a0490a3218770f
|
|
4
|
+
data.tar.gz: 3a0d1456f8c2bc573245e5c46afae6b2c83be393085bf6bebc5b28c06368d3f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 696026e2b9ca26c060c2b65a336f790ec193938a7740d8bdce3008c6bfae40cd80290077b717174554d7e6a1530e470f2523a5859b210c2bf9bd583e7dd72041
|
|
7
|
+
data.tar.gz: 42979948486f1e55f990bdbcc0ee2a697ffbf3c450b4013a7ae293e0960291533bfc4356fcfb8cfdeca5eae94d97a7ff522e2b5667cd1e9611de93cf39af560e
|
data/CHANGELOG.md
CHANGED
|
@@ -30,8 +30,9 @@ module Gapic
|
|
|
30
30
|
# @param initial_delay [Numeric] Initial delay in seconds.
|
|
31
31
|
# @param multiplier [Numeric] The delay scaling factor for each subsequent retry attempt.
|
|
32
32
|
# @param max_delay [Numeric] Maximum delay in seconds.
|
|
33
|
+
# @param jitter [Numeric] Random jitter added to the delay in seconds.
|
|
33
34
|
#
|
|
34
|
-
def initialize retry_codes: nil, initial_delay: nil, multiplier: nil, max_delay: nil
|
|
35
|
+
def initialize retry_codes: nil, initial_delay: nil, multiplier: nil, max_delay: nil, jitter: nil
|
|
35
36
|
super
|
|
36
37
|
end
|
|
37
38
|
end
|
|
@@ -31,6 +31,11 @@ module Gapic
|
|
|
31
31
|
# @return [Numeric] Default timeout threshold value in seconds.
|
|
32
32
|
DEFAULT_TIMEOUT = 3600 # One hour
|
|
33
33
|
|
|
34
|
+
# @private
|
|
35
|
+
# @return [Numeric] Default random jitter added to delay in seconds.
|
|
36
|
+
DEFAULT_JITTER = 1.0
|
|
37
|
+
private_constant :DEFAULT_JITTER
|
|
38
|
+
|
|
34
39
|
##
|
|
35
40
|
# Create new Gapic::Common::RetryPolicy instance.
|
|
36
41
|
#
|
|
@@ -39,14 +44,18 @@ module Gapic
|
|
|
39
44
|
# @param multiplier [Numeric] The delay scaling factor for each subsequent retry attempt.
|
|
40
45
|
# @param retry_codes [Array<String|Integer>] List of retry codes.
|
|
41
46
|
# @param timeout [Numeric] Timeout threshold value in seconds.
|
|
47
|
+
# @param jitter [Numeric] Random jitter added to the delay in seconds.
|
|
42
48
|
#
|
|
43
|
-
def initialize initial_delay: nil, max_delay: nil, multiplier: nil, retry_codes: nil, timeout: nil
|
|
49
|
+
def initialize initial_delay: nil, max_delay: nil, multiplier: nil, retry_codes: nil, timeout: nil, jitter: nil
|
|
50
|
+
raise ArgumentError, "jitter cannot be negative" if jitter&.negative?
|
|
51
|
+
|
|
44
52
|
# Instance values are set as `nil` to determine whether values are overriden from default.
|
|
45
53
|
@initial_delay = initial_delay
|
|
46
54
|
@max_delay = max_delay
|
|
47
55
|
@multiplier = multiplier
|
|
48
56
|
@retry_codes = convert_codes retry_codes
|
|
49
57
|
@timeout = timeout
|
|
58
|
+
@jitter = jitter
|
|
50
59
|
start!
|
|
51
60
|
end
|
|
52
61
|
|
|
@@ -75,6 +84,11 @@ module Gapic
|
|
|
75
84
|
@timeout || DEFAULT_TIMEOUT
|
|
76
85
|
end
|
|
77
86
|
|
|
87
|
+
# @return [Numeric] Random jitter added to the delay in seconds.
|
|
88
|
+
def jitter
|
|
89
|
+
@jitter || DEFAULT_JITTER
|
|
90
|
+
end
|
|
91
|
+
|
|
78
92
|
##
|
|
79
93
|
# Returns a duplicate in a non-executing state, i.e. with the deadline
|
|
80
94
|
# and current delay reset.
|
|
@@ -86,7 +100,8 @@ module Gapic
|
|
|
86
100
|
max_delay: @max_delay,
|
|
87
101
|
multiplier: @multiplier,
|
|
88
102
|
retry_codes: @retry_codes,
|
|
89
|
-
timeout: @timeout
|
|
103
|
+
timeout: @timeout,
|
|
104
|
+
jitter: @jitter
|
|
90
105
|
end
|
|
91
106
|
|
|
92
107
|
##
|
|
@@ -186,6 +201,7 @@ module Gapic
|
|
|
186
201
|
@initial_delay ||= retry_policy[:initial_delay]
|
|
187
202
|
@multiplier ||= retry_policy[:multiplier]
|
|
188
203
|
@max_delay ||= retry_policy[:max_delay]
|
|
204
|
+
@jitter ||= retry_policy[:jitter]
|
|
189
205
|
|
|
190
206
|
self
|
|
191
207
|
end
|
|
@@ -197,30 +213,34 @@ module Gapic
|
|
|
197
213
|
other.max_delay == max_delay &&
|
|
198
214
|
other.multiplier == multiplier &&
|
|
199
215
|
other.retry_codes == retry_codes &&
|
|
200
|
-
other.timeout == timeout
|
|
216
|
+
other.timeout == timeout &&
|
|
217
|
+
other.jitter == jitter
|
|
201
218
|
end
|
|
202
219
|
alias == eql?
|
|
203
220
|
|
|
204
221
|
# @private Hash code
|
|
205
222
|
def hash
|
|
206
|
-
[initial_delay, max_delay, multiplier, retry_codes, timeout].hash
|
|
223
|
+
[initial_delay, max_delay, multiplier, retry_codes, timeout, jitter].hash
|
|
207
224
|
end
|
|
208
225
|
|
|
209
226
|
private
|
|
210
227
|
|
|
211
228
|
# @private
|
|
229
|
+
# Perform the currently calculated delay, adding a jitter.
|
|
230
|
+
#
|
|
212
231
|
# @return [Numeric] The performed delay.
|
|
213
232
|
def delay!
|
|
233
|
+
delay_to_perform = [delay + Kernel.rand(0.0..jitter), max_delay].min
|
|
214
234
|
if @mock_time
|
|
215
|
-
@mock_time +=
|
|
216
|
-
@mock_delay_callback&.call
|
|
235
|
+
@mock_time += delay_to_perform
|
|
236
|
+
@mock_delay_callback&.call delay_to_perform
|
|
217
237
|
else
|
|
218
|
-
Kernel.sleep
|
|
238
|
+
Kernel.sleep delay_to_perform
|
|
219
239
|
end
|
|
220
240
|
end
|
|
221
241
|
|
|
222
242
|
# @private
|
|
223
|
-
# @return [Numeric] The new delay in seconds.
|
|
243
|
+
# @return [Numeric] The new delay (sans jitter) in seconds.
|
|
224
244
|
def increment_delay!
|
|
225
245
|
@delay = [delay * multiplier, max_delay].min
|
|
226
246
|
end
|
data/lib/gapic/common/version.rb
CHANGED
|
@@ -38,13 +38,15 @@ module Gapic
|
|
|
38
38
|
# @param multiplier [Numeric] The delay scaling factor for each subsequent retry attempt.
|
|
39
39
|
# @param max_delay [Numeric] Maximum delay in seconds.
|
|
40
40
|
# @param timeout [Numeric] Timeout threshold value in seconds.
|
|
41
|
+
# @param jitter [Numeric] Random jitter added to the delay in seconds.
|
|
41
42
|
#
|
|
42
|
-
def initialize initial_delay: nil, multiplier: nil, max_delay: nil, timeout: nil
|
|
43
|
+
def initialize initial_delay: nil, multiplier: nil, max_delay: nil, timeout: nil, jitter: nil
|
|
43
44
|
super(
|
|
44
45
|
initial_delay: initial_delay || DEFAULT_INITIAL_DELAY,
|
|
45
46
|
max_delay: max_delay || DEFAULT_MAX_DELAY,
|
|
46
47
|
multiplier: multiplier || DEFAULT_MULTIPLIER,
|
|
47
|
-
timeout: timeout || DEFAULT_TIMEOUT
|
|
48
|
+
timeout: timeout || DEFAULT_TIMEOUT,
|
|
49
|
+
jitter: jitter
|
|
48
50
|
)
|
|
49
51
|
end
|
|
50
52
|
end
|