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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89e34f73dc79fdd7911d7b95222437c9a36b3839
4
- data.tar.gz: 2e62a50a70a4b7848a66a84d1033d49194d09445
3
+ metadata.gz: 3d95423eb09fb3461645edb8f9457a9a6dc094c8
4
+ data.tar.gz: 6bbf73b5876f7993b1a04d701dbb2ba1a7794370
5
5
  SHA512:
6
- metadata.gz: 04a951e2106d61547d4409ebac4dcb2055c5d38012fc9b40cb97d46af7dfa9426fc27f7a27b7657e9587faf7d15d322d2e80a4b7f8da6967e2fc06edcff1458b
7
- data.tar.gz: 51ec22a345e521fc8adcfd7ec71a2bc488098d389b9b9463a51acd2ea262c86297d4d015fd5ceb8fb026eba9a9ecf6f82ed985f3dce62ee8641da7668f298e48
6
+ metadata.gz: afa9177aa3c48c6edffb13021095cf7cd660d83f4b192d4b4cc08353b086e708ec30f2da8f66e0fd174845dd52963d5e3e7563948d9d16d98297215dec874eb1
7
+ data.tar.gz: f38524a088d7cc795c5d13b9abc5b4bb873a25d282921decb03235acfbb9de5f0495afef5cb87438a3f186f971fee64bb600c6e19e67f38d865d3d20eb440d11
@@ -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
- unless @hosts.is_a? Array
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
- sleep delay
236
- delay = [@max_delay, delay * 2].min
237
- retry
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
 
@@ -1,3 +1,3 @@
1
1
  module InfluxDB
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -43,7 +43,7 @@ module InfluxDB
43
43
  check_background_queue(thread_num) until @queue.empty?
44
44
  end
45
45
 
46
- while true
46
+ while !client.stopped?
47
47
  self.check_background_queue(thread_num)
48
48
  sleep rand(SLEEP_INTERVAL)
49
49
  end
@@ -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",
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
  require 'timeout'
3
3
 
4
4
  describe InfluxDB::Worker do
5
- let(:fake_client) { double() }
5
+ let(:fake_client) { double(stopped?: false) }
6
6
  let(:worker) { InfluxDB::Worker.new(fake_client) }
7
7
 
8
8
  describe "#push" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Persen