sensu-transport 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sensu/transport/base.rb +6 -3
- data/lib/sensu/transport/rabbitmq.rb +16 -14
- data/sensu-transport.gemspec +1 -1
- data/spec/base_spec.rb +2 -1
- data/spec/rabbitmq_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6a38035e18fcea44cad21b1aba5594335e3ef30
|
4
|
+
data.tar.gz: 14eddc18dec551445e6fdd7d6341f807f774e82a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d3821c33f596ed82e10d4642d80c48d290842ff2e61c8b1f1dad518056e663280b59a0386139f791296c2733813e52d218b5e6ee079bc06429628929099e866
|
7
|
+
data.tar.gz: ee7e04f7c3b4c3df7dabf5d2a5ffff42f3b1f99e74f49639db6d4be540ae13da61a00ae4c82fd4eda7af5386e81544bf355e48aab443ee8b67d4d74bd92a6a27
|
data/lib/sensu/transport/base.rb
CHANGED
@@ -15,7 +15,7 @@ module Sensu
|
|
15
15
|
@after_reconnect = Proc.new {}
|
16
16
|
end
|
17
17
|
|
18
|
-
#
|
18
|
+
# Set the error callback.
|
19
19
|
#
|
20
20
|
# @param callback [Proc] called in the event of a transport
|
21
21
|
# error, the exception object should be passed as a parameter.
|
@@ -24,7 +24,7 @@ module Sensu
|
|
24
24
|
@on_error = callback
|
25
25
|
end
|
26
26
|
|
27
|
-
#
|
27
|
+
# Set the before reconnect callback.
|
28
28
|
#
|
29
29
|
# @param callback [Proc] called before attempting to reconnect
|
30
30
|
# to the transport.
|
@@ -33,7 +33,7 @@ module Sensu
|
|
33
33
|
@before_reconnect = callback
|
34
34
|
end
|
35
35
|
|
36
|
-
#
|
36
|
+
# Set the after reconnect callback.
|
37
37
|
#
|
38
38
|
# @param callback [Proc] called after reconnecting to the
|
39
39
|
# transport.
|
@@ -47,6 +47,9 @@ module Sensu
|
|
47
47
|
# @param options [Hash, String]
|
48
48
|
def connect(options={}); end
|
49
49
|
|
50
|
+
# Reconnect to the transport.
|
51
|
+
def reconnect; end
|
52
|
+
|
50
53
|
# Indicates if connected to the transport.
|
51
54
|
#
|
52
55
|
# @return [TrueClass, FalseClass]
|
@@ -13,27 +13,29 @@ module Sensu
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def connect(options={})
|
16
|
-
|
17
|
-
on_failure = on_connection_failure
|
16
|
+
create_connection_timeout
|
18
17
|
@connection = AMQP.connect(options, {
|
19
|
-
:on_tcp_connection_failure =>
|
20
|
-
:on_possible_authentication_failure =>
|
18
|
+
:on_tcp_connection_failure => on_connection_failure,
|
19
|
+
:on_possible_authentication_failure => on_connection_failure
|
21
20
|
})
|
22
21
|
@connection.logger = @logger
|
23
22
|
@connection.on_open do
|
24
|
-
|
23
|
+
@connection_timeout.cancel
|
25
24
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@connection.periodically_reconnect(5)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
@connection.on_tcp_connection_loss(&reconnect)
|
33
|
-
@connection.on_skipped_heartbeats(&reconnect)
|
25
|
+
reconnect_callback = Proc.new { reconnect }
|
26
|
+
@connection.on_tcp_connection_loss(&reconnect_callback)
|
27
|
+
@connection.on_skipped_heartbeats(&reconnect_callback)
|
34
28
|
setup_channel(options)
|
35
29
|
end
|
36
30
|
|
31
|
+
def reconnect
|
32
|
+
unless @connection.reconnecting?
|
33
|
+
@connection_timeout.cancel
|
34
|
+
@before_reconnect.call
|
35
|
+
@connection.periodically_reconnect(5)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
37
39
|
def connected?
|
38
40
|
@connection.connected?
|
39
41
|
end
|
@@ -98,7 +100,7 @@ module Sensu
|
|
98
100
|
private
|
99
101
|
|
100
102
|
def create_connection_timeout
|
101
|
-
EM::Timer.new(20) do
|
103
|
+
@connection_timeout = EM::Timer.new(20) do
|
102
104
|
error = Error.new("timed out while attempting to connect to rabbitmq")
|
103
105
|
@on_error.call(error)
|
104
106
|
end
|
data/sensu-transport.gemspec
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe "Sensu::Transport::Base" do
|
|
10
10
|
|
11
11
|
it "provides a transport API (noop)" do
|
12
12
|
@transport.should respond_to(:on_error, :before_reconnect, :after_reconnect,
|
13
|
-
:connect, :connected?, :close,
|
13
|
+
:connect, :reconnect, :connected?, :close,
|
14
14
|
:publish, :subscribe, :unsubscribe,
|
15
15
|
:acknowledge, :ack, :stats)
|
16
16
|
end
|
@@ -22,6 +22,7 @@ describe "Sensu::Transport::Base" do
|
|
22
22
|
@transport.after_reconnect(&callback).should be_an_instance_of(Proc)
|
23
23
|
@transport.connect.should eq(nil)
|
24
24
|
@transport.connect({}).should eq(nil)
|
25
|
+
@transport.reconnect.should eq(nil)
|
25
26
|
@transport.connected?.should eq(false)
|
26
27
|
@transport.close.should eq(nil)
|
27
28
|
@transport.publish("foo", "bar", "baz").should eq(nil)
|
data/spec/rabbitmq_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe "Sensu::Transport::RabbitMQ" do
|
|
13
13
|
|
14
14
|
it "provides a transport API" do
|
15
15
|
@transport.should respond_to(:on_error, :before_reconnect, :after_reconnect,
|
16
|
-
:connect, :connected?, :close,
|
16
|
+
:connect, :reconnect, :connected?, :close,
|
17
17
|
:publish, :subscribe, :unsubscribe,
|
18
18
|
:acknowledge, :ack, :stats)
|
19
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-transport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Porter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-em
|