riemann-client 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,8 +9,8 @@ Use
9
9
  ``` ruby
10
10
  require 'riemann/client'
11
11
 
12
- # Create a client. Host and port are optional.
13
- c = Riemann::Client.new host: 'localhost', port: 5555
12
+ # Create a client. Host, port and timeout are optional.
13
+ c = Riemann::Client.new host: 'localhost', port: 5555, timeout: 5
14
14
 
15
15
  # Send a simple event
16
16
  c << {service: 'testing', metric: 2.5}
@@ -3,6 +3,7 @@ module Riemann
3
3
 
4
4
  require 'rubygems'
5
5
  require 'beefcake'
6
+ require 'timeout'
6
7
  require 'riemann/version'
7
8
  require 'riemann/state'
8
9
  require 'riemann/attribute'
@@ -13,15 +13,17 @@ class Riemann::Client
13
13
 
14
14
  HOST = '127.0.0.1'
15
15
  PORT = 5555
16
+ TIMEOUT = 5
16
17
 
17
18
  require 'riemann/client/tcp'
18
19
  require 'riemann/client/udp'
19
20
 
20
- attr_accessor :host, :port, :tcp, :udp
21
+ attr_accessor :host, :port, :tcp, :udp, :timeout
21
22
 
22
23
  def initialize(opts = {})
23
24
  @host = opts[:host] || HOST
24
25
  @port = opts[:port] || PORT
26
+ @timeout = opts[:timeout] || TIMEOUT
25
27
  @udp = UDP.new opts
26
28
  @tcp = TCP.new opts
27
29
  end
@@ -6,11 +6,14 @@ module Riemann
6
6
  def initialize(opts = {})
7
7
  @host = opts[:host] || HOST
8
8
  @port = opts[:port] || PORT
9
+ @timeout = opts[:timeout] || TIMEOUT
9
10
  @locket = Mutex.new
10
11
  end
11
12
 
12
13
  def connect
13
- @socket = TCPSocket.new(@host, @port)
14
+ Timeout::timeout(@timeout) do
15
+ @socket = TCPSocket.new(@host, @port)
16
+ end
14
17
  end
15
18
 
16
19
  def close
@@ -20,7 +23,7 @@ module Riemann
20
23
  end
21
24
 
22
25
  def connected?
23
- not @socket.closed?
26
+ !@socket && @socket.closed?
24
27
  end
25
28
 
26
29
  # Read a message from a stream
@@ -78,6 +81,9 @@ module Riemann
78
81
  rescue InvalidResponse => e
79
82
  raise if tries > 3
80
83
  connect and retry
84
+ rescue Timeout::Error => e
85
+ raise if tries > 3
86
+ connect and retry
81
87
  end
82
88
  end
83
89
  end
@@ -23,7 +23,7 @@ module Riemann
23
23
  end
24
24
 
25
25
  def connected?
26
- not @socket.closed?
26
+ !!@socket && @socket.closed?
27
27
  end
28
28
 
29
29
  # Read a message from a stream
@@ -1,3 +1,3 @@
1
1
  module Riemann
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-02 00:00:00.000000000 Z
12
+ date: 2013-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: beefcake