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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4291b734210c6b32949c0025f343304de1c636ab00e0d2efdaeaf8e9eba3a51
4
- data.tar.gz: d3cd7f75b3d71a17dea16c1cd164d094c8b4c26b1a20e56c62df8c0d5778f80a
3
+ metadata.gz: 980789abe61ce0f5811b41b566af9c4a87c03223268af54dbc102a5147c50a9e
4
+ data.tar.gz: c01a90bcb753b210b41cbcfae8d54021465cf52a43c107642d1f2efcdb21dfeb
5
5
  SHA512:
6
- metadata.gz: b6375cc3204a5530b8c1b90c8376a63ce262c51cf0ef9ce998068c467390cd94d911c5be0ab16c5bb43522eddabb24b3af8e0de7261ad28baebfdea074d589bd
7
- data.tar.gz: 2fcbdcd001c5dc9d1c26320583c6f4a09debc1bbf89b461f0964abcbe4fc165ce7a1f98844c31f7fdeaea076d8c3383308cfc160850a5cde8acebbc28cadbe18
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.1', require: false # Unlicensed
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.12.1)
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.1)
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.77.0)
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.0)
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 (= 0.1.1)
220
+ wait_for (~> 0.1)
222
221
  webmock (~> 3.24)
223
222
  webrick (~> 1.9)
224
223
  yard (~> 0.9)
@@ -13,5 +13,5 @@
13
13
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
14
14
  # License:: MIT
15
15
  class BazaRb
16
- VERSION = '0.9.7'
16
+ VERSION = '0.9.9'
17
17
  end
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
- DEFAULT_CHUNK_SIZE = 4_000_000
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
- Typhoeus::Request.get(
702
- uri.to_s,
703
- headers:,
704
- connecttimeout: @timeout,
705
- timeout: @timeout
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|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baza.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko