radiator 0.2.3rc2 → 0.2.3rc3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c832e0ab4bf5f0426beb0b70df404dd97072d179
4
- data.tar.gz: e2e9752862b2759d54f204395b624779cfc2cf96
3
+ metadata.gz: e78f81905adcd6e53025310e30ad7565de743621
4
+ data.tar.gz: 950ee3b476e2f2effd2fb46227b7d3e2f4febf21
5
5
  SHA512:
6
- metadata.gz: 8d86849dee2532620c2e28a9623dbab64f7c49b46798009145daf30736b18a94b1a9cd1d2597e5b7860681007230d7bcf611073c8f0a4959899321cd50fc2145
7
- data.tar.gz: 19fe732cdd44863bb815d4e56637837bb014842a5a24acc396eaeb8f3621e7dc2c407b3f4f00c5c03395d3b6bd67a74b0d3589a53e9836d8c9e59132dd63b8f9
6
+ metadata.gz: 67c4da518dd163f3d2b9b50f7c01bff39ded3ee0040f639a1024a39537d55e291675c558b447af553167fad97e796d44d9ba5a3836bf5f9b753eeab36dbaf0b4
7
+ data.tar.gz: 3304790b68d3c98ff2bc6b2331732802caf150d7330a0789b98a844096606774a9ee84c9e23fcdfdc0acf0e4675f6537cf19f89edceb9952345de43bab97336d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- radiator (0.2.3rc2)
4
+ radiator (0.2.3rc3)
5
5
  bitcoin-ruby (= 0.0.10)
6
6
  ffi (= 1.9.18)
7
7
  hashie (~> 3.5, >= 3.5.5)
@@ -28,7 +28,7 @@ GEM
28
28
  multipart-post (>= 1.2, < 3)
29
29
  ffi (1.9.18)
30
30
  hashdiff (0.3.4)
31
- hashie (3.5.5)
31
+ hashie (3.5.6)
32
32
  json (1.8.6)
33
33
  little-plugger (1.1.4)
34
34
  logging (2.2.2)
data/README.md CHANGED
@@ -9,6 +9,13 @@
9
9
 
10
10
  Radiator is an API Client for interaction with the STEEM network using Ruby.
11
11
 
12
+ #### Fixes in v0.2.3
13
+
14
+ * Added low-level support for persistence and retrying API requests.
15
+ * Now using exponential back-off for retries.
16
+ * Detecting presence of `transaction_ids` (if enabled by the node).
17
+ * Default for `Hashie` warnings now go to `/dev/null`, where they belong.
18
+
12
19
  #### Fixes in v0.2.2
13
20
 
14
21
  * Gem updates
data/lib/radiator/api.rb CHANGED
@@ -14,8 +14,9 @@ module Radiator
14
14
  @debug = !!options[:debug]
15
15
  @net_http_persistent_enabled = true
16
16
  @logger = options[:logger] || Radiator.logger
17
+ @hashie_logger = options[:hashie_logger] || Logger.new('/dev/null')
17
18
 
18
- Hashie.logger = @logger
19
+ Hashie.logger = @hashie_logger
19
20
  @method_names = nil
20
21
  end
21
22
 
@@ -107,14 +108,68 @@ module Radiator
107
108
  id: rpc_id,
108
109
  method: "call"
109
110
  }
110
-
111
- response = request(options)
112
111
 
113
- if !!response
114
- response = JSON[response.body]
115
-
116
- Hashie::Mash.new(response)
117
- end
112
+ loop do
113
+ begin
114
+ response = request(options)
115
+
116
+ if !!response
117
+ case response.code
118
+ when '200'
119
+ response = JSON[response.body]
120
+
121
+ return Hashie::Mash.new(response)
122
+ when '400'
123
+ @logger.warn('Code 400: Bad Request, retrying ...')
124
+ backoff
125
+ redo
126
+ when '502'
127
+ @logger.warn('Code 502: Bad Gateway, retrying ...')
128
+ backoff
129
+ redo
130
+ when '503'
131
+ @logger.warn('Code 503: Service Unavailable, retrying ...')
132
+ backoff
133
+ redo
134
+ when '504'
135
+ @logger.warn('Code 504: Gateway Timeout, retrying ...')
136
+ backoff
137
+ redo
138
+ else
139
+ ap "Unknown code #{response.code}, retrying ..."
140
+ backoff
141
+ ap response
142
+ end
143
+ end
144
+
145
+ @logger.error("No response.")
146
+ break
147
+ rescue Errno::ECONNREFUSED => e
148
+ @logger.warn('Connection refused, retrying ...')
149
+ backoff
150
+ redo
151
+ rescue Errno::EADDRNOTAVAIL => e
152
+ @logger.warn('Node not available, retrying ...')
153
+ backoff
154
+ redo
155
+ rescue Net::ReadTimeout => e
156
+ @logger.warn('Node read timeout, retrying ...')
157
+ backoff
158
+ redo
159
+ rescue Net::OpenTimeout => e
160
+ @logger.warn('Node timeout, retrying ...')
161
+ backoff
162
+ redo
163
+ rescue RangeError => e
164
+ @logger.warn('Range Error, retrying ...')
165
+ backoff
166
+ redo
167
+ rescue => e
168
+ puts "Unknown exception from request ..."
169
+ backoff
170
+ ap e
171
+ end
172
+ end # loop
118
173
  end
119
174
 
120
175
  def shutdown
@@ -152,16 +207,20 @@ module Radiator
152
207
  end
153
208
  end
154
209
 
210
+ def post_request
211
+ Net::HTTP::Post.new uri.request_uri, 'Content-Type' => 'application/json'
212
+ end
213
+
155
214
  def request(options)
156
215
  if !!@net_http_persistent_enabled
157
216
  begin
158
- request = Net::HTTP::Post.new uri.request_uri, 'Content-Type' => 'application/json'
217
+ request = post_request
159
218
  request.body = JSON[options]
160
219
 
161
220
  if (response = http.request(uri, request)).kind_of? Net::HTTPSuccess
162
221
  return response
163
222
  else
164
- @logger.warn "Unexpeced response: #{response}"
223
+ @logger.warn "Unexpeced response: #{response.inspect}; temporarily falling back to non-persistent-http"
165
224
  end
166
225
  rescue Net::HTTP::Persistent::Error => e
167
226
  @logger.warn "Unable to perform request: #{request} :: #{e}: #{e.backtrace}"
@@ -171,12 +230,29 @@ module Radiator
171
230
  end
172
231
 
173
232
  unless @net_http_persistent_enabled
174
- @http = Net::HTTP.new(uri.host, uri.port)
175
- @http.use_ssl = true
176
- @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
177
- request = Net::HTTP::Post.new uri.request_uri, 'Content-Type' => 'application/json'
233
+ non_persistent_http = Net::HTTP.new(uri.host, uri.port)
234
+ non_persistent_http.use_ssl = true
235
+ non_persistent_http.verify_mode = OpenSSL::SSL::VERIFY_NONE
236
+ request = post_request
178
237
  request.body = JSON[options]
179
- @http.request(request)
238
+
239
+ # Try to go back to http persistent on next request.
240
+ @net_http_persistent_enabled = true
241
+
242
+ non_persistent_http.request(request)
243
+ end
244
+ end
245
+
246
+ def backoff
247
+ @backoff_at ||= Time.now
248
+ @backoff_sleep ||= 0.01
249
+
250
+ @backoff_sleep *= 2
251
+ sleep @backoff_sleep
252
+
253
+ if Time.now - @backoff_at > 300
254
+ @backoff_at = nil
255
+ @backoff_sleep = nil
180
256
  end
181
257
  end
182
258
  end
@@ -140,7 +140,11 @@ module Radiator
140
140
  return _transactions unless !!block
141
141
 
142
142
  _transactions.each_with_index do |transaction, index|
143
- yield transaction, b['transaction_ids'][index]
143
+ trx_id = if !!b['transaction_ids']
144
+ b['transaction_ids'][index]
145
+ end
146
+
147
+ yield transaction, trx_id
144
148
  end
145
149
  end
146
150
  end
@@ -1,3 +1,3 @@
1
1
  module Radiator
2
- VERSION = '0.2.3rc2'
2
+ VERSION = '0.2.3rc3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3rc2
4
+ version: 0.2.3rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-03 00:00:00.000000000 Z
11
+ date: 2017-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -410,7 +410,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
410
410
  version: 1.3.1
411
411
  requirements: []
412
412
  rubyforge_project:
413
- rubygems_version: 2.4.8
413
+ rubygems_version: 2.6.12
414
414
  signing_key:
415
415
  specification_version: 4
416
416
  summary: STEEM RPC Ruby Client