influxdb 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/influxdb/client.rb +20 -10
- data/lib/influxdb/version.rb +1 -1
- data/lib/influxdb/worker.rb +1 -1
- data/spec/influxdb/client_spec.rb +32 -0
- data/spec/influxdb/worker_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d95423eb09fb3461645edb8f9457a9a6dc094c8
|
4
|
+
data.tar.gz: 6bbf73b5876f7993b1a04d701dbb2ba1a7794370
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afa9177aa3c48c6edffb13021095cf7cd660d83f4b192d4b4cc08353b086e708ec30f2da8f66e0fd174845dd52963d5e3e7563948d9d16d98297215dec874eb1
|
7
|
+
data.tar.gz: f38524a088d7cc795c5d13b9abc5b4bb873a25d282921decb03235acfbb9de5f0495afef5cb87438a3f186f971fee64bb600c6e19e67f38d865d3d20eb440d11
|
data/lib/influxdb/client.rb
CHANGED
@@ -11,7 +11,8 @@ module InfluxDB
|
|
11
11
|
:password,
|
12
12
|
:database,
|
13
13
|
:time_precision,
|
14
|
-
:use_ssl
|
14
|
+
:use_ssl,
|
15
|
+
:stopped
|
15
16
|
|
16
17
|
attr_accessor :queue, :worker
|
17
18
|
|
@@ -41,7 +42,7 @@ module InfluxDB
|
|
41
42
|
def initialize *args
|
42
43
|
@database = args.first if args.first.is_a? String
|
43
44
|
opts = args.last.is_a?(Hash) ? args.last : {}
|
44
|
-
@hosts = opts[:hosts] || opts[:host] || ["localhost"]
|
45
|
+
@hosts = Array(opts[:hosts] || opts[:host] || ["localhost"])
|
45
46
|
@port = opts[:port] || 8086
|
46
47
|
@username = opts[:username] || "root"
|
47
48
|
@password = opts[:password] || "root"
|
@@ -55,9 +56,7 @@ module InfluxDB
|
|
55
56
|
|
56
57
|
@worker = InfluxDB::Worker.new(self) if @async
|
57
58
|
|
58
|
-
|
59
|
-
@hosts = [@hosts]
|
60
|
-
end
|
59
|
+
at_exit { stop! }
|
61
60
|
end
|
62
61
|
|
63
62
|
## allow options, e.g. influxdb.create_database('foo', replicationFactor: 3)
|
@@ -168,6 +167,14 @@ module InfluxDB
|
|
168
167
|
end
|
169
168
|
end
|
170
169
|
|
170
|
+
def stop!
|
171
|
+
@stopped = true
|
172
|
+
end
|
173
|
+
|
174
|
+
def stopped?
|
175
|
+
@stopped
|
176
|
+
end
|
177
|
+
|
171
178
|
private
|
172
179
|
def full_url(path, params=nil)
|
173
180
|
"".tap do |url|
|
@@ -229,12 +236,15 @@ module InfluxDB
|
|
229
236
|
block.call(http)
|
230
237
|
|
231
238
|
rescue Timeout::Error, *InfluxDB::NET_HTTP_EXCEPTIONS => e
|
232
|
-
log :error, "Failed to contact host #{host}: #{e.inspect} - retrying in #{delay}s."
|
239
|
+
log :error, "Failed to contact host #{host}: #{e.inspect} #{"- retrying in #{delay}s." unless stopped?}"
|
233
240
|
log :info, "Queue size is #{@queue.length}." unless @queue.nil?
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
241
|
+
if stopped?
|
242
|
+
raise e
|
243
|
+
else
|
244
|
+
sleep delay
|
245
|
+
delay = [@max_delay, delay * 2].min
|
246
|
+
retry
|
247
|
+
end
|
238
248
|
end
|
239
249
|
end
|
240
250
|
|
data/lib/influxdb/version.rb
CHANGED
data/lib/influxdb/worker.rb
CHANGED
@@ -259,6 +259,38 @@ describe InfluxDB::Client do
|
|
259
259
|
@influxdb.write_point("seriez", data).should be_a(Net::HTTPOK)
|
260
260
|
end
|
261
261
|
|
262
|
+
describe "retrying requests" do
|
263
|
+
let(:body) do
|
264
|
+
[{
|
265
|
+
"name" => "seriez",
|
266
|
+
"points" => [[87, "juan"]],
|
267
|
+
"columns" => ["age", "name"]
|
268
|
+
}]
|
269
|
+
end
|
270
|
+
|
271
|
+
let(:data) { {:name => "juan", :age => 87} }
|
272
|
+
|
273
|
+
subject { @influxdb.write_point("seriez", data) }
|
274
|
+
|
275
|
+
before do
|
276
|
+
allow(@influxdb).to receive(:log)
|
277
|
+
stub_request(:post, "http://influxdb.test:9999/db/database/series").with(
|
278
|
+
:query => {:u => "username", :p => "password", :time_precision => "s"},
|
279
|
+
:body => body
|
280
|
+
).to_raise(Timeout::Error).then.to_return(:status => 200)
|
281
|
+
end
|
282
|
+
|
283
|
+
it "retries on http errors when not stopped" do
|
284
|
+
expect(subject).to be_a(Net::HTTPOK)
|
285
|
+
end
|
286
|
+
|
287
|
+
it "raises when stopped" do
|
288
|
+
@influxdb.stop!
|
289
|
+
expect { subject }.to raise_error(Timeout::Error)
|
290
|
+
end
|
291
|
+
|
292
|
+
end
|
293
|
+
|
262
294
|
it "raise an exception if the server didn't return 200" do
|
263
295
|
body = [{
|
264
296
|
"name" => "seriez",
|