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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49dd0eac66fa87b0721be113bef63fef2b1a6e5a940e1d7b50d9cce9e09862d0
4
- data.tar.gz: a5f9e460e9ba4aeda8dce60fe3c09921fa7041d977c530c6b917c695c98a41c2
3
+ metadata.gz: fcbc7506438df13060cabc32fb5d87bb684a10a63f045d3d204788751f8e8ab5
4
+ data.tar.gz: 1e672c028f2b97bed37fedb335d9dd535a625295cbcd8592909ddf865d26b551
5
5
  SHA512:
6
- metadata.gz: 19be699a163f2d53d927ff05c787e449efe72b444660218544c2ffb84e91e28a3bd42e2731dbf1a8d4f4726cd02f52d6d39b4f1188838febc56ffe26f003fbf6
7
- data.tar.gz: 75145b1a1f5266f18f25ec956c6ef22b252729834a0af61289c5203c4a0133b78b2f303b33928457fa501b2ad0e4ff0a5b8564855146ecf2bab1c4d57d225778
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.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.8'
16
+ VERSION = '0.9.10'
17
17
  end
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
- Typhoeus::Request.get(
705
- uri.to_s,
706
- headers:,
707
- connecttimeout: @timeout,
708
- timeout: @timeout
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|
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.8
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko