kontent-delivery-sdk-ruby 2.0.10 → 2.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/delivery/client/request_manager.rb +19 -7
- data/lib/delivery/tests/429.json +5 -0
- data/lib/delivery/tests/fake_responder.rb +7 -0
- data/lib/delivery/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10a1940690541523126a2bd9f3767e54a68de48c14ca7acfb311f392e0cb3707
|
4
|
+
data.tar.gz: 80b485b19bef5ddc40e8964133b96dc0c1d3543f2c477c704973502c86495832
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e11259c855f2dc4caf3146a704b0330acf6314d68cff4259a1acb03c60bee8359b567f68d10c033e2fef3bd36a51da864f8f5501485b032e05feba6b37f0a57b
|
7
|
+
data.tar.gz: 0a4ab01bb8be8744d83faf31ed25e35fa986b1fedaf531e7c85978138a3e58563ead1e5d19ba42e494af9d79ba73bedc87e3f1c0ea80088582a3b06790f6dbeb
|
data/README.md
CHANGED
@@ -97,15 +97,16 @@ You can then request the secure published content in your project. Be sure to no
|
|
97
97
|
|
98
98
|
### Retry policy
|
99
99
|
|
100
|
-
By default, the SDK uses a retry policy, asking for requested content again in case of an error. The default policy retries the HTTP
|
100
|
+
By default, the SDK uses a retry policy, asking for requested content again in case of an error. The default policy retries the HTTP request if the following status codes are returned:
|
101
101
|
|
102
102
|
* 408 - `RequestTimeout`
|
103
|
+
* 429 - `TooManyRequests`
|
103
104
|
* 500 - `InternalServerError`
|
104
105
|
* 502 - `BadGateway`
|
105
106
|
* 503 - `ServiceUnavailable`
|
106
107
|
* 504 - `GatewayTimeout`
|
107
108
|
|
108
|
-
The
|
109
|
+
The SDK will perform a total of 6 attempts at a maximum of 30 seconds to retrieve content before returning a `ResponseBase` object containing the error. The consecutive attempts are delayed with [exponential backoff and jitter](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/).
|
109
110
|
|
110
111
|
To disable the retry policy, you can use the `with_retry_policy` argument:
|
111
112
|
|
@@ -7,8 +7,10 @@ module Kentico
|
|
7
7
|
class RequestManager
|
8
8
|
class << self
|
9
9
|
MAX_ATTEMPTS = 6
|
10
|
-
|
11
|
-
|
10
|
+
MAX_DELAY_SECONDS = 30
|
11
|
+
INITIAL_DELAY = 1
|
12
|
+
RETRY_WHEN_CODE = [408, 429, 500, 502, 503, 504].freeze
|
13
|
+
CODES_WITH_POSSIBLE_RETRY_HEADER = [429, 503].freeze
|
12
14
|
|
13
15
|
def start(query, headers)
|
14
16
|
@query = query
|
@@ -16,6 +18,7 @@ module Kentico
|
|
16
18
|
@times_run = 1
|
17
19
|
@delay = INITIAL_DELAY
|
18
20
|
@url = @query.provide_url
|
21
|
+
@total_delay = 0
|
19
22
|
continue
|
20
23
|
end
|
21
24
|
|
@@ -23,19 +26,28 @@ module Kentico
|
|
23
26
|
|
24
27
|
def should_retry(potential_response)
|
25
28
|
return potential_response if @times_run == MAX_ATTEMPTS ||
|
26
|
-
|
27
|
-
|
29
|
+
!RETRY_WHEN_CODE.include?(potential_response.http_code) ||
|
30
|
+
!@query.with_retry_policy ||
|
31
|
+
@total_delay >= MAX_DELAY_SECONDS
|
28
32
|
|
29
|
-
|
30
|
-
@delay *= 2
|
33
|
+
next_delay
|
31
34
|
sleep(@delay)
|
35
|
+
@total_delay += @delay
|
32
36
|
continue
|
33
37
|
end
|
34
38
|
|
39
|
+
# Generates a random delay based on times_run, then increases times_run
|
40
|
+
def next_delay
|
41
|
+
min = 0.8 * INITIAL_DELAY
|
42
|
+
max = (1.2 * INITIAL_DELAY) * (2**@times_run)
|
43
|
+
@delay = rand(min..max)
|
44
|
+
@times_run += 1
|
45
|
+
end
|
46
|
+
|
35
47
|
def continue
|
36
48
|
if ENV['TEST'] == '1'
|
37
49
|
resp = Kentico::Kontent::Delivery::Tests::FakeResponder.get_response @query, @url, @headers
|
38
|
-
return resp if resp.is_a? Kentico::Kontent::Delivery::Responses::ResponseBase
|
50
|
+
return should_retry(resp) if resp.is_a? Kentico::Kontent::Delivery::Responses::ResponseBase
|
39
51
|
|
40
52
|
make_response resp # resp is pure JSON
|
41
53
|
else
|
@@ -32,6 +32,8 @@ module Kentico
|
|
32
32
|
url[BASE_URL.length...url.length]
|
33
33
|
end
|
34
34
|
|
35
|
+
return respond_429 if @query.code_name == '429'
|
36
|
+
|
35
37
|
qs = url.contains('?') ? url.split('?')[1] : nil
|
36
38
|
return respond_filtering qs unless qs.nil? # e.g. /items/about_us?skip=0&limit=5
|
37
39
|
|
@@ -65,6 +67,11 @@ module Kentico
|
|
65
67
|
##Kentico::Kontent::Delivery::Responses::ResponseBase.new 200, '', '', path.read if path.exist?
|
66
68
|
end
|
67
69
|
|
70
|
+
def respond_429
|
71
|
+
path = Pathname.new(File.dirname(__FILE__) + '/429.json')
|
72
|
+
Kentico::Kontent::Delivery::Responses::ResponseBase.new 429, '', '', path.read if path.exist?
|
73
|
+
end
|
74
|
+
|
68
75
|
def respond_401
|
69
76
|
path = Pathname.new(File.dirname(__FILE__) + '/401.json')
|
70
77
|
Kentico::Kontent::Delivery::Responses::ResponseBase.new 401, '', '', path.read if path.exist?
|
data/lib/delivery/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kontent-delivery-sdk-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Dugre
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- lib/delivery/responses/delivery_type_response.rb
|
156
156
|
- lib/delivery/responses/response_base.rb
|
157
157
|
- lib/delivery/tests/401.json
|
158
|
+
- lib/delivery/tests/429.json
|
158
159
|
- lib/delivery/tests/fake_responder.rb
|
159
160
|
- lib/delivery/tests/filtering/items_gt.json
|
160
161
|
- lib/delivery/tests/filtering/items_with_count.json
|