baza.rb 0.9.9 → 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 +42 -17
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 980789abe61ce0f5811b41b566af9c4a87c03223268af54dbc102a5147c50a9e
4
- data.tar.gz: c01a90bcb753b210b41cbcfae8d54021465cf52a43c107642d1f2efcdb21dfeb
3
+ metadata.gz: f94511fc54301a20314e8d456a708e37a1cea845db41e9e2f88389f574f76e8f
4
+ data.tar.gz: 97d8b8027bca5379934eec24aacd006209b3fc0e316f94f90c4ad33c1d64aa05
5
5
  SHA512:
6
- metadata.gz: eab49fdb4389c82f56f43ce05ad3ec526d56b48b61eff07fa9c67cfb48ef93e2ffcd60f7acdf535e4b2cf301bb35a85a8dee7f85521085d445253b0d135455ed
7
- data.tar.gz: 477a00b39bb00e5315a24d60eb888a4915cb9c374bc3c12245b74917b3788919a44971937e1fad3f1267a06c3c371ab846ed5acce73097fa93611601e090366f
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.9'
16
+ VERSION = '0.9.11'
17
17
  end
data/lib/baza-rb.rb CHANGED
@@ -652,9 +652,30 @@ class BazaRb
652
652
  attempt = 0
653
653
  loop do
654
654
  ret = yield
655
- if ret.code == 429 && attempt < 3
655
+ if ret.code == 429 && attempt < 5
656
656
  attempt += 1
657
- sleep(2**attempt)
657
+ seconds = 2**attempt
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...")
678
+ sleep(seconds)
658
679
  next
659
680
  end
660
681
  return ret
@@ -691,7 +712,7 @@ class BazaRb
691
712
  when 500
692
713
  msg +=
693
714
  ", most probably it's an internal error on the server, " \
694
- 'please report this to https://github.com/zerocracy/baza'
715
+ 'please report this to https://github.com/zerocracy/baza.rb'
695
716
  when 503
696
717
  msg +=
697
718
  ", most probably it's an internal error on the server (#{headers['X-Zerocracy-Failure'].inspect}), " \
@@ -718,13 +739,15 @@ class BazaRb
718
739
  def get(uri, allowed = [200])
719
740
  retry_it do
720
741
  checked(
721
- retry_if_server_busy do
722
- Typhoeus::Request.get(
723
- uri.to_s,
724
- headers:,
725
- connecttimeout: @timeout,
726
- timeout: @timeout
727
- )
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
728
751
  end,
729
752
  allowed
730
753
  )
@@ -741,13 +764,15 @@ class BazaRb
741
764
  def post(uri, params, allowed = [302])
742
765
  retry_it do
743
766
  checked(
744
- Typhoeus::Request.post(
745
- uri.to_s,
746
- body: params.merge('_csrf' => csrf),
747
- headers:,
748
- connecttimeout: @timeout,
749
- timeout: @timeout
750
- ),
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,
751
776
  allowed
752
777
  )
753
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.9
4
+ version: 0.9.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko