radiator 0.2.3 → 0.3.0dev1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +6 -6
- data/lib/radiator/api.rb +89 -53
- data/lib/radiator/version.rb +1 -1
- data/radiator.gemspec +2 -2
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db2757e072c1d05c7f12eb6228245cb66680af4a
|
4
|
+
data.tar.gz: 33ade0af04c25fdae0dce9bf94322367d68cfbe3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c5a3a4079b0f5d92f142fee590f3e6e0256bdba99c2f78951f2030dc68ad4f3f42cc6fd013293cab4342b596be3789432acea19f518de5cf06a8097da1048c1
|
7
|
+
data.tar.gz: 836ea02d0e39a9ac338b301ff65ed9efc8256336b3fccc482e377f573d131970459cb4dee3af3102c49583b61b308a8e77b1241cbca9cdd2755f8bc901285de8
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
radiator (0.
|
4
|
+
radiator (0.3.0dev1)
|
5
5
|
bitcoin-ruby (= 0.0.11)
|
6
6
|
ffi (= 1.9.18)
|
7
7
|
hashie (~> 3.5, >= 3.5.5)
|
8
|
-
json (~>
|
8
|
+
json (~> 2.0, >= 2.0.2)
|
9
9
|
logging (~> 2.2, >= 2.2.0)
|
10
10
|
net-http-persistent (~> 2.9, >= 2.9.4)
|
11
11
|
|
@@ -29,7 +29,7 @@ GEM
|
|
29
29
|
ffi (1.9.18)
|
30
30
|
hashdiff (0.3.6)
|
31
31
|
hashie (3.5.6)
|
32
|
-
json (
|
32
|
+
json (2.0.2)
|
33
33
|
little-plugger (1.1.4)
|
34
34
|
logging (2.2.2)
|
35
35
|
little-plugger (~> 1.1)
|
@@ -48,9 +48,9 @@ GEM
|
|
48
48
|
public_suffix (3.0.0)
|
49
49
|
rake (11.3.0)
|
50
50
|
safe_yaml (1.0.4)
|
51
|
-
simplecov (0.
|
51
|
+
simplecov (0.15.1)
|
52
52
|
docile (~> 1.1.0)
|
53
|
-
json (
|
53
|
+
json (>= 1.8, < 3)
|
54
54
|
simplecov-html (~> 0.10.0)
|
55
55
|
simplecov-html (0.10.2)
|
56
56
|
slop (3.6.0)
|
@@ -76,7 +76,7 @@ DEPENDENCIES
|
|
76
76
|
pry (~> 0.10.3)
|
77
77
|
radiator!
|
78
78
|
rake (~> 11.2, >= 11.2.2)
|
79
|
-
simplecov (~> 0.
|
79
|
+
simplecov (~> 0.15.1)
|
80
80
|
typhoeus (~> 1.0, >= 1.0.2)
|
81
81
|
vcr (~> 2.9, >= 2.9.2)
|
82
82
|
webmock (~> 2.1, >= 2.1.0)
|
data/lib/radiator/api.rb
CHANGED
@@ -7,14 +7,36 @@ require 'net/http/persistent'
|
|
7
7
|
|
8
8
|
module Radiator
|
9
9
|
class Api
|
10
|
+
DEFAULT_URL = 'https://steemd.steemit.com'
|
11
|
+
|
12
|
+
DEFAULT_FAILOVER_URLS = [
|
13
|
+
DEFAULT_URL,
|
14
|
+
'https://steemd.steemitdev.com',
|
15
|
+
'https://steemd-int.steemit.com',
|
16
|
+
'https://steemd.steemitstage.com',
|
17
|
+
'https://gtg.steem.house:8090',
|
18
|
+
'https://rpc.steemliberator.com'
|
19
|
+
]
|
20
|
+
|
21
|
+
POST_HEADERS = {
|
22
|
+
'Content-Type' => 'application/json'
|
23
|
+
}
|
24
|
+
|
10
25
|
def initialize(options = {})
|
11
26
|
@user = options[:user]
|
12
27
|
@password = options[:password]
|
13
|
-
@url = options[:url] ||
|
28
|
+
@url = options[:url] || DEFAULT_URL
|
29
|
+
@preferred_url = @url.dup
|
30
|
+
@failover_urls = options[:failover_urls] || (DEFAULT_FAILOVER_URLS - [@url])
|
31
|
+
@preferred_failover_urls = @failover_urls.dup
|
14
32
|
@debug = !!options[:debug]
|
15
33
|
@net_http_persistent_enabled = true
|
16
34
|
@logger = options[:logger] || Radiator.logger
|
17
|
-
@hashie_logger = options[:hashie_logger] || Logger.new(
|
35
|
+
@hashie_logger = options[:hashie_logger] || Logger.new(nil)
|
36
|
+
|
37
|
+
unless @hashie_logger.respond_to? :warn
|
38
|
+
@hashie_logger = Logger.new(@hashie_logger)
|
39
|
+
end
|
18
40
|
|
19
41
|
Hashie.logger = @hashie_logger
|
20
42
|
@method_names = nil
|
@@ -113,59 +135,53 @@ module Radiator
|
|
113
135
|
begin
|
114
136
|
response = request(options)
|
115
137
|
|
116
|
-
if
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
end
|
138
|
+
if response.nil?
|
139
|
+
@logger.error "No response, retrying ..."
|
140
|
+
backoff
|
141
|
+
redo
|
142
|
+
end
|
143
|
+
|
144
|
+
case response.code
|
145
|
+
when '200'
|
146
|
+
response = JSON[response.body]
|
147
|
+
|
148
|
+
return Hashie::Mash.new(response)
|
149
|
+
when '400'
|
150
|
+
@logger.warn 'Code 400: Bad Request, retrying ...'
|
151
|
+
when '502'
|
152
|
+
@logger.warn 'Code 502: Bad Gateway, retrying ...'
|
153
|
+
when '503'
|
154
|
+
@logger.warn 'Code 503: Service Unavailable, retrying ...'
|
155
|
+
when '504'
|
156
|
+
@logger.warn 'Code 504: Gateway Timeout, retrying ...'
|
157
|
+
else
|
158
|
+
@logger.warn "Unknown code #{response.code}, retrying ..."
|
159
|
+
ap response
|
139
160
|
end
|
140
161
|
|
141
|
-
@logger.error("No response.")
|
142
|
-
break
|
143
|
-
rescue Errno::ECONNREFUSED => e
|
144
|
-
@logger.warn('Connection refused, retrying ...')
|
145
162
|
backoff
|
163
|
+
rescue Errno::ECONNREFUSED => e
|
164
|
+
@logger.warn 'Connection refused, retrying ...'
|
146
165
|
rescue Errno::EADDRNOTAVAIL => e
|
147
|
-
@logger.warn
|
148
|
-
backoff
|
166
|
+
@logger.warn 'Node not available, retrying ...'
|
149
167
|
rescue Net::ReadTimeout => e
|
150
|
-
@logger.warn
|
151
|
-
backoff
|
168
|
+
@logger.warn 'Node read timeout, retrying ...'
|
152
169
|
rescue Net::OpenTimeout => e
|
153
|
-
@logger.warn
|
154
|
-
backoff
|
170
|
+
@logger.warn 'Node timeout, retrying ...'
|
155
171
|
rescue RangeError => e
|
156
|
-
@logger.warn
|
157
|
-
backoff
|
172
|
+
@logger.warn 'Range Error, retrying ...'
|
158
173
|
rescue OpenSSL::SSL::SSLError => e
|
159
|
-
@logger.warn
|
160
|
-
backoff
|
174
|
+
@logger.warn "SSL Error (#{e.message}), retrying ..."
|
161
175
|
rescue SocketError => e
|
162
|
-
@logger.warn
|
163
|
-
|
176
|
+
@logger.warn "Socket Error (#{e.message}), retrying ..."
|
177
|
+
rescue JSON::ParserError => e
|
178
|
+
@logger.warn "JSON Parse Error (#{e.message}), retrying ..."
|
164
179
|
rescue => e
|
165
|
-
|
180
|
+
@logger.warn "Unknown exception from request ..."
|
166
181
|
ap e
|
167
|
-
backoff
|
168
182
|
end
|
183
|
+
|
184
|
+
backoff
|
169
185
|
end # loop
|
170
186
|
end
|
171
187
|
|
@@ -184,12 +200,12 @@ module Radiator
|
|
184
200
|
e if e['api'].to_sym == api_name
|
185
201
|
end.compact.freeze
|
186
202
|
end
|
187
|
-
|
203
|
+
|
188
204
|
def rpc_id
|
189
205
|
@rpc_id ||= 0
|
190
206
|
@rpc_id = @rpc_id + 1
|
191
207
|
end
|
192
|
-
|
208
|
+
|
193
209
|
def uri
|
194
210
|
@uri ||= URI.parse(@url)
|
195
211
|
end
|
@@ -205,7 +221,7 @@ module Radiator
|
|
205
221
|
end
|
206
222
|
|
207
223
|
def post_request
|
208
|
-
Net::HTTP::Post.new uri.request_uri,
|
224
|
+
Net::HTTP::Post.new uri.request_uri, POST_HEADERS
|
209
225
|
end
|
210
226
|
|
211
227
|
def request(options)
|
@@ -213,17 +229,17 @@ module Radiator
|
|
213
229
|
begin
|
214
230
|
request = post_request
|
215
231
|
request.body = JSON[options]
|
232
|
+
response = http.request(uri, request)
|
216
233
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
end
|
234
|
+
return response if response.kind_of? Net::HTTPSuccess
|
235
|
+
@logger.warn "Unexpeced response: #{response.inspect}; temporarily falling back to non-persistent-http"
|
236
|
+
backoff
|
237
|
+
@net_http_persistent_enabled = false
|
222
238
|
rescue Net::HTTP::Persistent::Error => e
|
223
239
|
@logger.warn "Unable to perform request: #{request} :: #{e} :: #{!!e.cause ? "cause: #{e.cause.message}" : ''}; temporarily falling back to non-persistent-http"
|
240
|
+
backoff
|
241
|
+
@net_http_persistent_enabled = false
|
224
242
|
end
|
225
|
-
|
226
|
-
@net_http_persistent_enabled = false
|
227
243
|
end
|
228
244
|
|
229
245
|
unless @net_http_persistent_enabled
|
@@ -240,7 +256,27 @@ module Radiator
|
|
240
256
|
end
|
241
257
|
end
|
242
258
|
|
259
|
+
def reset_failover
|
260
|
+
@url = @preferred_url.dup
|
261
|
+
@failover_urls = @preferred_failover_urls.dup
|
262
|
+
@logger.warn "Failover reset, going back to #{@url} ..."
|
263
|
+
end
|
264
|
+
|
265
|
+
def pop_failover_url
|
266
|
+
@failover_urls.delete(@failover_urls.sample) || @url
|
267
|
+
end
|
268
|
+
|
269
|
+
def bump_failover
|
270
|
+
reset_failover if @failover_urls.none?
|
271
|
+
|
272
|
+
@uri = nil
|
273
|
+
@url = pop_failover_url
|
274
|
+
@logger.warn "Failing over to #{@url} ..."
|
275
|
+
end
|
276
|
+
|
243
277
|
def backoff
|
278
|
+
shutdown
|
279
|
+
bump_failover if !!@backoff_at && Time.now - @backoff_at < 300
|
244
280
|
@backoff_at ||= Time.now
|
245
281
|
@backoff_sleep ||= 0.01
|
246
282
|
|
data/lib/radiator/version.rb
CHANGED
data/radiator.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'minitest', '~> 5.9', '>= 5.9.0'
|
23
23
|
spec.add_development_dependency 'minitest-line', '~> 0.6.3'
|
24
24
|
spec.add_development_dependency 'webmock', '~> 2.1', '>= 2.1.0'
|
25
|
-
spec.add_development_dependency 'simplecov', '~> 0.
|
25
|
+
spec.add_development_dependency 'simplecov', '~> 0.15.1'
|
26
26
|
spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.5.2'
|
27
27
|
spec.add_development_dependency 'vcr', '~> 2.9', '>= 2.9.2'
|
28
28
|
spec.add_development_dependency 'faraday', '~> 0.9.2'
|
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
# Maximum for net-http-persistent is 2.9.4, required by ruby-2.0.0-p645, which
|
35
35
|
# is the darwin default at the moment.
|
36
36
|
spec.add_dependency('net-http-persistent', '~> 2.9', '>= 2.9.4')
|
37
|
-
spec.add_dependency('json', '~>
|
37
|
+
spec.add_dependency('json', '~> 2.0', '>= 2.0.2')
|
38
38
|
spec.add_dependency('logging', '~> 2.2', '>= 2.2.0')
|
39
39
|
spec.add_dependency('hashie', '~> 3.5', '>= 3.5.5')
|
40
40
|
spec.add_dependency('bitcoin-ruby', '0.0.11')
|
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.
|
4
|
+
version: 0.3.0dev1
|
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-09-
|
11
|
+
date: 2017-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,14 +110,14 @@ dependencies:
|
|
110
110
|
requirements:
|
111
111
|
- - "~>"
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version: 0.
|
113
|
+
version: 0.15.1
|
114
114
|
type: :development
|
115
115
|
prerelease: false
|
116
116
|
version_requirements: !ruby/object:Gem::Requirement
|
117
117
|
requirements:
|
118
118
|
- - "~>"
|
119
119
|
- !ruby/object:Gem::Version
|
120
|
-
version: 0.
|
120
|
+
version: 0.15.1
|
121
121
|
- !ruby/object:Gem::Dependency
|
122
122
|
name: codeclimate-test-reporter
|
123
123
|
requirement: !ruby/object:Gem::Requirement
|
@@ -260,20 +260,20 @@ dependencies:
|
|
260
260
|
requirements:
|
261
261
|
- - "~>"
|
262
262
|
- !ruby/object:Gem::Version
|
263
|
-
version: '
|
263
|
+
version: '2.0'
|
264
264
|
- - ">="
|
265
265
|
- !ruby/object:Gem::Version
|
266
|
-
version:
|
266
|
+
version: 2.0.2
|
267
267
|
type: :runtime
|
268
268
|
prerelease: false
|
269
269
|
version_requirements: !ruby/object:Gem::Requirement
|
270
270
|
requirements:
|
271
271
|
- - "~>"
|
272
272
|
- !ruby/object:Gem::Version
|
273
|
-
version: '
|
273
|
+
version: '2.0'
|
274
274
|
- - ">="
|
275
275
|
- !ruby/object:Gem::Version
|
276
|
-
version:
|
276
|
+
version: 2.0.2
|
277
277
|
- !ruby/object:Gem::Dependency
|
278
278
|
name: logging
|
279
279
|
requirement: !ruby/object:Gem::Requirement
|
@@ -405,12 +405,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
405
405
|
version: '0'
|
406
406
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
407
407
|
requirements:
|
408
|
-
- - "
|
408
|
+
- - ">"
|
409
409
|
- !ruby/object:Gem::Version
|
410
|
-
version:
|
410
|
+
version: 1.3.1
|
411
411
|
requirements: []
|
412
412
|
rubyforge_project:
|
413
|
-
rubygems_version: 2.
|
413
|
+
rubygems_version: 2.6.13
|
414
414
|
signing_key:
|
415
415
|
specification_version: 4
|
416
416
|
summary: STEEM RPC Ruby Client
|