miasma 0.2.12 → 0.2.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/miasma/types/api.rb +32 -1
- data/lib/miasma/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 245960ddc013bc31980e434709199977532bdc4b
|
4
|
+
data.tar.gz: a62c8ccb2f4a5d097bd1096bf6612a6614e62410
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e38b67ea2b1ae9cd546bc229958cf49f56f6b32a5b81a694cd1ecffa689574e894d67a48423d2d268f861b36fe01e5d7613b93b2fa5e2364a3dc32dab76a099
|
7
|
+
data.tar.gz: b08eac5bdf5ce4724981af35310a2b2108b856c8806bc0f99c5cb09c540afa4c6d7b3e03eb83733d583ddd49ef9d6ac14cb8546cc09de09e9e9b7a6c667966b3
|
data/CHANGELOG.md
CHANGED
data/lib/miasma/types/api.rb
CHANGED
@@ -6,6 +6,13 @@ module Miasma
|
|
6
6
|
# Remote API connection
|
7
7
|
class Api
|
8
8
|
|
9
|
+
# HTTP request methods that are allowed retry
|
10
|
+
VALID_REQUEST_RETRY_METHODS=[:get, :head]
|
11
|
+
# Maximum allowed HTTP request retries (for non-HTTP related errors)
|
12
|
+
MAX_REQUEST_RETRIES=5
|
13
|
+
# Seconds to pause between retries
|
14
|
+
REQUEST_RETRY_DELAY=0.5
|
15
|
+
|
9
16
|
include Miasma::Utils::Lazy
|
10
17
|
include Miasma::Utils::Memoization
|
11
18
|
|
@@ -93,13 +100,37 @@ module Miasma
|
|
93
100
|
else
|
94
101
|
_connection = connection
|
95
102
|
end
|
96
|
-
result =
|
103
|
+
result = retryable_request(http_method) do
|
104
|
+
make_request(_connection, http_method, request_args)
|
105
|
+
end
|
97
106
|
unless([args.fetch(:expects, 200)].flatten.compact.map(&:to_i).include?(result.code))
|
98
107
|
raise Error::ApiError::RequestError.new(result.reason, :response => result)
|
99
108
|
end
|
100
109
|
format_response(result, !args[:disable_body_extraction])
|
101
110
|
end
|
102
111
|
|
112
|
+
# If HTTP request method is allowed to be retried then retry
|
113
|
+
# request on non-response failures. Otherwise just re-raise
|
114
|
+
# immediately
|
115
|
+
#
|
116
|
+
# @param http_method [Symbol] HTTP request method
|
117
|
+
# @yield request to be retried if allowed
|
118
|
+
# @return [Object] result of block
|
119
|
+
def retryable_request(http_method)
|
120
|
+
attempts = VALID_REQUEST_RETRY_METHODS.include?(http_method) ? 0 :nil
|
121
|
+
begin
|
122
|
+
yield
|
123
|
+
rescue => e
|
124
|
+
if(attempts && attempts < MAX_REQUEST_RETRIES)
|
125
|
+
attempts += 1
|
126
|
+
sleep RETRY_REQUEST_DELAY
|
127
|
+
retry
|
128
|
+
else
|
129
|
+
raise
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
103
134
|
# Perform request
|
104
135
|
#
|
105
136
|
# @param connection [HTTP]
|
data/lib/miasma/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miasma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|