ocean-rails 4.0.4 → 4.0.5
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/ocean/api.rb +25 -23
- data/lib/ocean/api_remote_resource.rb +1 -0
- data/lib/ocean/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5349c1dc1cf8eeaf2c770d4e814b545390033d2f
|
4
|
+
data.tar.gz: 8e6790b74505ad7133671bfe3b7b7c44f2edebcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e2081aff6a3aef06d4f7c88c7320c7a27a3d18e64c3615ee19d260c7ca3d372a53c8198c1d9b26e016ffcfc632891bfe9d640a15d852d494ef684162c4e3b72
|
7
|
+
data.tar.gz: 597f1ab3c2a6dc78aa8d25d68b32d09a11a8b049c7648b232b60637d90603428fe365c75b35446432c176c768695b6626d3295a26d0c528cc7af6a6a19157715
|
data/lib/ocean/api.rb
CHANGED
@@ -181,11 +181,13 @@ class Api
|
|
181
181
|
headers['X-API-Token'] = x_api_token if x_api_token.present?
|
182
182
|
headers['X-Metadata'] = x_metadata if x_metadata.present?
|
183
183
|
|
184
|
-
retries = 0 unless http_method.to_s.upcase
|
184
|
+
retries = 0 unless ["GET", "HEAD"].include? http_method.to_s.upcase
|
185
185
|
|
186
186
|
@hydra ||= Typhoeus::Hydra.hydra
|
187
|
-
|
187
|
+
|
188
|
+
request = nil
|
188
189
|
response = nil
|
190
|
+
response_getter = lambda { response }
|
189
191
|
|
190
192
|
url = url.first == "/" ? "#{INTERNAL_OCEAN_API_URL}#{url}" : Api.internalize_uri(url)
|
191
193
|
|
@@ -199,18 +201,18 @@ class Api
|
|
199
201
|
body: body,
|
200
202
|
ssl_verifypeer: ssl_verifypeer,
|
201
203
|
ssl_verifyhost: ssl_verifyhost)
|
202
|
-
|
203
204
|
# Define a callback to process the response and do retries
|
204
205
|
request.on_complete do |typhoeus_response|
|
205
|
-
response = Response.new
|
206
|
+
response = Response.new typhoeus_response
|
206
207
|
case response.status
|
207
208
|
when 100..199
|
208
209
|
enqueue_request.call # Ignore and retry
|
209
210
|
when 200..299, 304
|
210
|
-
# Success, call the post-processor if any
|
211
|
-
|
212
|
-
|
213
|
-
|
211
|
+
# Success, call the post-processor if any. Any further Api.request
|
212
|
+
# calls done by the post-processor will use the same response
|
213
|
+
# accessors, which means the final result will be what the last
|
214
|
+
# post-processor to finish returns.
|
215
|
+
response = block.call(response) if block
|
214
216
|
when 300..399
|
215
217
|
nil # Done, redirect
|
216
218
|
when 400, 419
|
@@ -231,11 +233,11 @@ class Api
|
|
231
233
|
when 400..499
|
232
234
|
nil # Done, fail
|
233
235
|
else
|
234
|
-
# Retry if there are any retries left
|
236
|
+
# We got a 5xx. Retry if there are any retries left
|
235
237
|
if retries > 0
|
236
238
|
retries -= 1
|
237
239
|
sleep backoff_time
|
238
|
-
backoff_time = [backoff_time + backoff_time * backoff_rate,
|
240
|
+
backoff_time = [backoff_time + backoff_time * backoff_rate, backoff_max].min
|
239
241
|
enqueue_request.call
|
240
242
|
else
|
241
243
|
nil # Done, don't retry
|
@@ -251,27 +253,27 @@ class Api
|
|
251
253
|
|
252
254
|
# So create and enqueue the request
|
253
255
|
enqueue_request.call
|
254
|
-
#
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
end
|
263
|
-
return response
|
256
|
+
# If doing parallel calls, return a lambda which returns the final response
|
257
|
+
return response_getter if Api.simultaneously?
|
258
|
+
# Run it now. Blocks until completed, possibly after any number of retries
|
259
|
+
@hydra.run
|
260
|
+
if response.is_a?(Response)
|
261
|
+
# Raise any exceptions
|
262
|
+
raise Api::TimeoutError, "Api.request timed out" if response.timed_out?
|
263
|
+
raise Api::NoResponseError, "Api.request could not obtain a response" if response.status == 0
|
264
264
|
end
|
265
|
-
|
266
|
-
nil
|
265
|
+
response_getter.call
|
267
266
|
end
|
268
267
|
|
269
268
|
|
270
269
|
def self.simultaneously (&block)
|
271
270
|
raise "block required" unless block
|
272
271
|
@inside_simultaneously = true
|
272
|
+
results = []
|
273
273
|
@hydra = nil
|
274
|
-
block.call
|
274
|
+
block.call(results)
|
275
|
+
@hydra.run if @hydra
|
276
|
+
results.map(&:call)
|
275
277
|
ensure
|
276
278
|
@inside_simultaneously = false
|
277
279
|
end
|
data/lib/ocean/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ocean-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Bengtson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -283,7 +283,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
283
283
|
version: '0'
|
284
284
|
requirements: []
|
285
285
|
rubyforge_project:
|
286
|
-
rubygems_version: 2.2.
|
286
|
+
rubygems_version: 2.2.2
|
287
287
|
signing_key:
|
288
288
|
specification_version: 4
|
289
289
|
summary: This gem implements common Ocean behaviour for Ruby and Ruby on Rails.
|