baza.rb 0.9.10 → 0.9.11

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/baza-rb/version.rb +1 -1
  3. data/lib/baza-rb.rb +40 -18
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcbc7506438df13060cabc32fb5d87bb684a10a63f045d3d204788751f8e8ab5
4
- data.tar.gz: 1e672c028f2b97bed37fedb335d9dd535a625295cbcd8592909ddf865d26b551
3
+ metadata.gz: f94511fc54301a20314e8d456a708e37a1cea845db41e9e2f88389f574f76e8f
4
+ data.tar.gz: 97d8b8027bca5379934eec24aacd006209b3fc0e316f94f90c4ad33c1d64aa05
5
5
  SHA512:
6
- metadata.gz: d6300c6a5a7ee6fcd2de409901b42b3331166470348510721a3b5bbd667f69351de04cb52409b68a116cd22bea5aaa7a8c963c7167112467a3afb92796fa5aa5
7
- data.tar.gz: fc58aab87af51e458bc6a20b91693f83f8a32507c504efcabc214fbd6e9be6c4402325bb4154326a9d8def4faed26a8ecf450251540a00cb89d1f0774f7308a5
6
+ metadata.gz: 4217832c03755e02d6b2c619282105069f1c9131d690704e2918d2dfeee8343f6511095e27e94a46fb9336063f6470057289befb89714eccc5437a8fd05ff2cb
7
+ data.tar.gz: 72fd3aabcf03aef3010bafe9659dd5d54e882dffcad12bf8ab0e79e6dad0f34acd5dcf77db7dfe053c740681359d32141863c72676bad489502c29cafe17b63e
@@ -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.10'
16
+ VERSION = '0.9.11'
17
17
  end
data/lib/baza-rb.rb CHANGED
@@ -644,19 +644,37 @@ 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.
647
+ # Execute a block with retries on 429 status codes.
648
648
  #
649
649
  # @yield The block to execute with retries
650
650
  # @return [Object] The result of the block execution
651
651
  def retry_if_server_busy(&)
652
- allowed = [429, 500]
653
652
  attempt = 0
654
653
  loop do
655
654
  ret = yield
656
- if allowed.include?(ret.code) && attempt < 5
655
+ if ret.code == 429 && attempt < 5
657
656
  attempt += 1
658
657
  seconds = 2**attempt
659
- @loog.info("Now, will sleep for #{seconds} and try again...")
658
+ @loog.info("Server seems to be busy, will sleep for #{seconds} and try again...")
659
+ sleep(seconds)
660
+ next
661
+ end
662
+ return ret
663
+ end
664
+ end
665
+
666
+ # Execute a block with retries on 500 status codes.
667
+ #
668
+ # @yield The block to execute with retries
669
+ # @return [Object] The result of the block execution
670
+ def retry_if_server_failed(&)
671
+ attempt = 0
672
+ loop do
673
+ ret = yield
674
+ if ret.code >= 500 && attempt < 5
675
+ attempt += 1
676
+ seconds = 2**attempt
677
+ @loog.info("Server seems to be in trouble, will sleep for #{seconds} and try again...")
660
678
  sleep(seconds)
661
679
  next
662
680
  end
@@ -721,13 +739,15 @@ class BazaRb
721
739
  def get(uri, allowed = [200])
722
740
  retry_it do
723
741
  checked(
724
- retry_if_server_busy do
725
- Typhoeus::Request.get(
726
- uri.to_s,
727
- headers:,
728
- connecttimeout: @timeout,
729
- timeout: @timeout
730
- )
742
+ retry_if_server_failed do
743
+ retry_if_server_busy do
744
+ Typhoeus::Request.get(
745
+ uri.to_s,
746
+ headers:,
747
+ connecttimeout: @timeout,
748
+ timeout: @timeout
749
+ )
750
+ end
731
751
  end,
732
752
  allowed
733
753
  )
@@ -744,13 +764,15 @@ class BazaRb
744
764
  def post(uri, params, allowed = [302])
745
765
  retry_it do
746
766
  checked(
747
- Typhoeus::Request.post(
748
- uri.to_s,
749
- body: params.merge('_csrf' => csrf),
750
- headers:,
751
- connecttimeout: @timeout,
752
- timeout: @timeout
753
- ),
767
+ retry_if_server_failed do
768
+ Typhoeus::Request.post(
769
+ uri.to_s,
770
+ body: params.merge('_csrf' => csrf),
771
+ headers:,
772
+ connecttimeout: @timeout,
773
+ timeout: @timeout
774
+ )
775
+ end,
754
776
  allowed
755
777
  )
756
778
  end
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.10
4
+ version: 0.9.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko