baza.rb 0.9.7 → 0.9.9
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 +30 -8
- 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: 980789abe61ce0f5811b41b566af9c4a87c03223268af54dbc102a5147c50a9e
|
4
|
+
data.tar.gz: c01a90bcb753b210b41cbcfae8d54021465cf52a43c107642d1f2efcdb21dfeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eab49fdb4389c82f56f43ce05ad3ec526d56b48b61eff07fa9c67cfb48ef93e2ffcd60f7acdf535e4b2cf301bb35a85a8dee7f85521085d445253b0d135455ed
|
7
|
+
data.tar.gz: 477a00b39bb00e5315a24d60eb888a4915cb9c374bc3c12245b74917b3788919a44971937e1fad3f1267a06c3c371ab846ed5acce73097fa93611601e090366f
|
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
@@ -31,8 +31,11 @@ require_relative 'baza-rb/version'
|
|
31
31
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
32
32
|
# License:: MIT
|
33
33
|
class BazaRb
|
34
|
-
# How big are the chunks we send, by default, in bytes
|
35
|
-
|
34
|
+
# How big are the chunks we send, by default, in bytes.
|
35
|
+
# Numbers larger than 1Mb may lead to problems with the server,
|
36
|
+
# since sending time will be too long and the server may drop
|
37
|
+
# connections. Better keep it as is: 1Mb.
|
38
|
+
DEFAULT_CHUNK_SIZE = 1_000_000
|
36
39
|
|
37
40
|
# When the server failed (503).
|
38
41
|
class ServerFailure < StandardError; end
|
@@ -641,6 +644,23 @@ class BazaRb
|
|
641
644
|
with_retries(max_tries: @retries, rescue: TimedOut, &)
|
642
645
|
end
|
643
646
|
|
647
|
+
# Execute a block with retries on 429 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
|
+
attempt = 0
|
653
|
+
loop do
|
654
|
+
ret = yield
|
655
|
+
if ret.code == 429 && attempt < 3
|
656
|
+
attempt += 1
|
657
|
+
sleep(2**attempt)
|
658
|
+
next
|
659
|
+
end
|
660
|
+
return ret
|
661
|
+
end
|
662
|
+
end
|
663
|
+
|
644
664
|
# Check the HTTP response and return it.
|
645
665
|
#
|
646
666
|
# @param [Typhoeus::Response] ret The response
|
@@ -698,12 +718,14 @@ class BazaRb
|
|
698
718
|
def get(uri, allowed = [200])
|
699
719
|
retry_it do
|
700
720
|
checked(
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
721
|
+
retry_if_server_busy do
|
722
|
+
Typhoeus::Request.get(
|
723
|
+
uri.to_s,
|
724
|
+
headers:,
|
725
|
+
connecttimeout: @timeout,
|
726
|
+
timeout: @timeout
|
727
|
+
)
|
728
|
+
end,
|
707
729
|
allowed
|
708
730
|
)
|
709
731
|
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|
|