tsd_client 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/tsd_client.rb +25 -6
  3. metadata +8 -9
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2bc9f6302790c9d8dd80fa8f41839c3762f74905
4
+ data.tar.gz: f436bf3a22b20757d363c8e20febdaf8c24de4e5
5
+ SHA512:
6
+ metadata.gz: 5c6dbe2b7e5a55602f4f81b85478f573e3caa21cdaf90004bf45320d153c08898124c5890b6db2756f693dd94cf1626d1941b3b74a99f72cc08d9446c0dabee7
7
+ data.tar.gz: 061acaac4300163e5a437985132634f08deb06a75835aa442082f6288b20f3c8556a47b635f4203ee7b021d4034e446b6a3ed216f2f8fce6d9f8df28bbc35596
data/lib/tsd_client.rb CHANGED
@@ -12,7 +12,15 @@ module TSD
12
12
  host: '0.0.0.0',
13
13
  port: 4242,
14
14
  timeout: 120, # seconds
15
+ retries: 3,
16
+ retry_interval: 1, # second
15
17
  }.merge options
18
+
19
+ connect
20
+ end
21
+
22
+ def connect
23
+ @socket = TCPSocket.open @options[:host], @options[:port]
16
24
  end
17
25
 
18
26
  def query options
@@ -34,15 +42,26 @@ module TSD
34
42
  end
35
43
  end
36
44
 
37
- def put options
45
+ def put options, retries = @options[:retries]
38
46
  Timeout::timeout @options[:timeout] do
39
- TCPSocket.open @options[:host], @options[:port] do |socket|
40
- socket.puts Format.put options
41
-
42
- response, _, _ = socket.recvmsg_nonblock rescue nil
47
+ begin
48
+ @socket.puts Format.put options
49
+ response, _, _ = @socket.recvmsg_nonblock rescue nil
43
50
  response.chomp if response
51
+ rescue Exception => e
52
+ if retries > 0
53
+ sleep @options[:retry_interval]
54
+ $stderr.puts "Error: #{e}, retrying \##{retries}"
55
+ retries -= 1
56
+ # try to reconnect
57
+ connect
58
+ retry
59
+ else
60
+ raise e
61
+ end
44
62
  end
45
63
  end
46
64
  end
65
+
47
66
  end
48
- end
67
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tsd_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Dallas Marlow
8
+ - Shangpeng Sun
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-26 00:00:00.000000000 Z
12
+ date: 2016-02-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -22,26 +22,25 @@ files:
22
22
  - lib/tsd_client/format.rb
23
23
  homepage: https://github.com/dallasmarlow/tsd_client
24
24
  licenses: []
25
+ metadata: {}
25
26
  post_install_message:
26
27
  rdoc_options: []
27
28
  require_paths:
28
29
  - lib
29
30
  required_ruby_version: !ruby/object:Gem::Requirement
30
- none: false
31
31
  requirements:
32
- - - ! '>='
32
+ - - '>='
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  required_rubygems_version: !ruby/object:Gem::Requirement
36
- none: false
37
36
  requirements:
38
- - - ! '>='
37
+ - - '>='
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
41
40
  requirements: []
42
41
  rubyforge_project:
43
- rubygems_version: 1.8.23
42
+ rubygems_version: 2.0.14
44
43
  signing_key:
45
- specification_version: 3
44
+ specification_version: 4
46
45
  summary: OpenTSDB client
47
46
  test_files: []