miasma 0.2.12 → 0.2.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7396d4fda42e875b71624a0eca9ab303a606140
4
- data.tar.gz: dc2d67fa4c59fdb2a0d0411bfbb099f91bc753dc
3
+ metadata.gz: 245960ddc013bc31980e434709199977532bdc4b
4
+ data.tar.gz: a62c8ccb2f4a5d097bd1096bf6612a6614e62410
5
5
  SHA512:
6
- metadata.gz: 4c58428f59a25b11576541387304375e4d7232c0016fbcef9fbaa5dfb746eda92a85cad33d7fc474e808c11ded50425b4699618fb6cec67c6a81be5728346a4c
7
- data.tar.gz: 361b96d5a94c44335cc68f34b4cb7b36006cd85c270189aedb4356480dd17c5064d1da12a1702c20158a5ca87457681b3aca5a6d3f26a317309135ed11a83f2d
6
+ metadata.gz: 3e38b67ea2b1ae9cd546bc229958cf49f56f6b32a5b81a694cd1ecffa689574e894d67a48423d2d268f861b36fe01e5d7613b93b2fa5e2364a3dc32dab76a099
7
+ data.tar.gz: b08eac5bdf5ce4724981af35310a2b2108b856c8806bc0f99c5cb09c540afa4c6d7b3e03eb83733d583ddd49ef9d6ac14cb8546cc09de09e9e9b7a6c667966b3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # v0.2.14
2
+ * Add non-response failure retry support on non-modify requests
3
+
1
4
  # v0.2.12
2
5
  * Extract provider implementations to standalone libraries
3
6
  * Add test helper executable
@@ -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 = make_request(_connection, http_method, request_args)
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]
@@ -1,4 +1,4 @@
1
1
  module Miasma
2
2
  # current library version
3
- VERSION = Gem::Version.new('0.2.12')
3
+ VERSION = Gem::Version.new('0.2.14')
4
4
  end
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.12
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 00:00:00.000000000 Z
11
+ date: 2015-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie