baza.rb 0.9.8 → 0.9.10
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/Gemfile +1 -2
- data/Gemfile.lock +5 -6
- data/lib/baza-rb/version.rb +1 -1
- data/lib/baza-rb.rb +29 -7
- data/test/test_baza-rb.rb +12 -0
- 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: fcbc7506438df13060cabc32fb5d87bb684a10a63f045d3d204788751f8e8ab5
|
4
|
+
data.tar.gz: 1e672c028f2b97bed37fedb335d9dd535a625295cbcd8592909ddf865d26b551
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6300c6a5a7ee6fcd2de409901b42b3331166470348510721a3b5bbd667f69351de04cb52409b68a116cd22bea5aaa7a8c963c7167112467a3afb92796fa5aa5
|
7
|
+
data.tar.gz: fc58aab87af51e458bc6a20b91693f83f8a32507c504efcabc214fbd6e9be6c4402325bb4154326a9d8def4faed26a8ecf450251540a00cb89d1f0774f7308a5
|
data/Gemfile
CHANGED
@@ -10,7 +10,6 @@ gem 'base64', '~>0.3', require: false
|
|
10
10
|
gem 'factbase', '~>0.11', require: false
|
11
11
|
gem 'minitest', '~>5.25', require: false
|
12
12
|
gem 'minitest-reporters', '~>1.7', require: false
|
13
|
-
gem 'nio4r', '2.7.4', require: false # GPL
|
14
13
|
gem 'online', '~>0.0', require: false
|
15
14
|
gem 'os', '~>1.1', require: false
|
16
15
|
gem 'puma', '~>6.6', require: false
|
@@ -26,7 +25,7 @@ gem 'rubocop-rake', '~>0.7', require: false
|
|
26
25
|
gem 'simplecov', '~>0.22', require: false
|
27
26
|
gem 'simplecov-cobertura', '~>2.1', require: false
|
28
27
|
gem 'sinatra', '~>4.1', require: false
|
29
|
-
gem 'wait_for', '0.1
|
28
|
+
gem 'wait_for', '~>0.1', require: false
|
30
29
|
gem 'webmock', '~>3.24', require: false
|
31
30
|
gem 'webrick', '~>1.9', require: false
|
32
31
|
gem 'yard', '~>0.9', require: false
|
data/Gemfile.lock
CHANGED
@@ -36,7 +36,7 @@ GEM
|
|
36
36
|
ellipsized (0.3.0)
|
37
37
|
ethon (0.16.0)
|
38
38
|
ffi (>= 1.15.0)
|
39
|
-
factbase (0.
|
39
|
+
factbase (0.13.0)
|
40
40
|
backtrace (~> 0.4)
|
41
41
|
decoor (~> 0.0)
|
42
42
|
ellipsized (~> 0.3)
|
@@ -47,7 +47,7 @@ GEM
|
|
47
47
|
others (~> 0.0)
|
48
48
|
tago (~> 0.0)
|
49
49
|
yaml (~> 0.3)
|
50
|
-
faraday (2.13.
|
50
|
+
faraday (2.13.2)
|
51
51
|
faraday-net_http (>= 2.0, < 3.5)
|
52
52
|
json
|
53
53
|
logger
|
@@ -126,7 +126,7 @@ GEM
|
|
126
126
|
regexp_parser (2.10.0)
|
127
127
|
retries (0.0.5)
|
128
128
|
rexml (3.4.1)
|
129
|
-
rubocop (1.
|
129
|
+
rubocop (1.78.0)
|
130
130
|
json (~> 2.3)
|
131
131
|
language_server-protocol (~> 3.17.0.2)
|
132
132
|
lint_roller (~> 1.1.0)
|
@@ -170,7 +170,7 @@ GEM
|
|
170
170
|
rack-session (>= 2.0.0, < 3)
|
171
171
|
tilt (~> 2.0)
|
172
172
|
tago (0.1.0)
|
173
|
-
tilt (2.6.
|
173
|
+
tilt (2.6.1)
|
174
174
|
timeout (0.4.3)
|
175
175
|
typhoeus (1.4.1)
|
176
176
|
ethon (>= 0.9.0)
|
@@ -202,7 +202,6 @@ DEPENDENCIES
|
|
202
202
|
factbase (~> 0.11)
|
203
203
|
minitest (~> 5.25)
|
204
204
|
minitest-reporters (~> 1.7)
|
205
|
-
nio4r (= 2.7.4)
|
206
205
|
online (~> 0.0)
|
207
206
|
os (~> 1.1)
|
208
207
|
puma (~> 6.6)
|
@@ -218,7 +217,7 @@ DEPENDENCIES
|
|
218
217
|
simplecov (~> 0.22)
|
219
218
|
simplecov-cobertura (~> 2.1)
|
220
219
|
sinatra (~> 4.1)
|
221
|
-
wait_for (
|
220
|
+
wait_for (~> 0.1)
|
222
221
|
webmock (~> 3.24)
|
223
222
|
webrick (~> 1.9)
|
224
223
|
yard (~> 0.9)
|
data/lib/baza-rb/version.rb
CHANGED
data/lib/baza-rb.rb
CHANGED
@@ -644,6 +644,26 @@ class BazaRb
|
|
644
644
|
with_retries(max_tries: @retries, rescue: TimedOut, &)
|
645
645
|
end
|
646
646
|
|
647
|
+
# Execute a block with retries on 429 and 500 status codes.
|
648
|
+
#
|
649
|
+
# @yield The block to execute with retries
|
650
|
+
# @return [Object] The result of the block execution
|
651
|
+
def retry_if_server_busy(&)
|
652
|
+
allowed = [429, 500]
|
653
|
+
attempt = 0
|
654
|
+
loop do
|
655
|
+
ret = yield
|
656
|
+
if allowed.include?(ret.code) && attempt < 5
|
657
|
+
attempt += 1
|
658
|
+
seconds = 2**attempt
|
659
|
+
@loog.info("Now, will sleep for #{seconds} and try again...")
|
660
|
+
sleep(seconds)
|
661
|
+
next
|
662
|
+
end
|
663
|
+
return ret
|
664
|
+
end
|
665
|
+
end
|
666
|
+
|
647
667
|
# Check the HTTP response and return it.
|
648
668
|
#
|
649
669
|
# @param [Typhoeus::Response] ret The response
|
@@ -674,7 +694,7 @@ class BazaRb
|
|
674
694
|
when 500
|
675
695
|
msg +=
|
676
696
|
", most probably it's an internal error on the server, " \
|
677
|
-
'please report this to https://github.com/zerocracy/baza'
|
697
|
+
'please report this to https://github.com/zerocracy/baza.rb'
|
678
698
|
when 503
|
679
699
|
msg +=
|
680
700
|
", most probably it's an internal error on the server (#{headers['X-Zerocracy-Failure'].inspect}), " \
|
@@ -701,12 +721,14 @@ class BazaRb
|
|
701
721
|
def get(uri, allowed = [200])
|
702
722
|
retry_it do
|
703
723
|
checked(
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
724
|
+
retry_if_server_busy do
|
725
|
+
Typhoeus::Request.get(
|
726
|
+
uri.to_s,
|
727
|
+
headers:,
|
728
|
+
connecttimeout: @timeout,
|
729
|
+
timeout: @timeout
|
730
|
+
)
|
731
|
+
end,
|
710
732
|
allowed
|
711
733
|
)
|
712
734
|
end
|
data/test/test_baza-rb.rb
CHANGED
@@ -693,6 +693,18 @@ class TestBazaRb < Minitest::Test
|
|
693
693
|
baza.push('test', 'data', [])
|
694
694
|
end
|
695
695
|
|
696
|
+
def test_get_request_retries_on_429_status_code
|
697
|
+
WebMock.disable_net_connect!
|
698
|
+
stub_request(:get, 'https://example.org:443/whoami')
|
699
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
700
|
+
.to_return(status: 429)
|
701
|
+
.times(3)
|
702
|
+
stub_request(:get, 'https://example.org:443/whoami')
|
703
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
704
|
+
.to_return(status: 200, body: 'testuser')
|
705
|
+
assert_equal('testuser', fake_baza.whoami)
|
706
|
+
end
|
707
|
+
|
696
708
|
def test_durable_load_from_sinatra
|
697
709
|
WebMock.enable_net_connect!
|
698
710
|
Dir.mktmpdir do |dir|
|