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.
- checksums.yaml +4 -4
- data/lib/baza-rb/version.rb +1 -1
- data/lib/baza-rb.rb +40 -18
- 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: f94511fc54301a20314e8d456a708e37a1cea845db41e9e2f88389f574f76e8f
|
4
|
+
data.tar.gz: 97d8b8027bca5379934eec24aacd006209b3fc0e316f94f90c4ad33c1d64aa05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4217832c03755e02d6b2c619282105069f1c9131d690704e2918d2dfeee8343f6511095e27e94a46fb9336063f6470057289befb89714eccc5437a8fd05ff2cb
|
7
|
+
data.tar.gz: 72fd3aabcf03aef3010bafe9659dd5d54e882dffcad12bf8ab0e79e6dad0f34acd5dcf77db7dfe053c740681359d32141863c72676bad489502c29cafe17b63e
|
data/lib/baza-rb/version.rb
CHANGED
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
|
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
|
655
|
+
if ret.code == 429 && attempt < 5
|
657
656
|
attempt += 1
|
658
657
|
seconds = 2**attempt
|
659
|
-
@loog.info("
|
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
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
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
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
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
|