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.
- checksums.yaml +4 -4
- data/lib/baza-rb/version.rb +1 -1
- data/lib/baza-rb.rb +42 -17
- 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
@@ -652,9 +652,30 @@ class BazaRb
|
|
652
652
|
attempt = 0
|
653
653
|
loop do
|
654
654
|
ret = yield
|
655
|
-
if ret.code == 429 && attempt <
|
655
|
+
if ret.code == 429 && attempt < 5
|
656
656
|
attempt += 1
|
657
|
-
|
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
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
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
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
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
|