rabbitmq-cluster 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,5 +11,5 @@ server.start
11
11
 
12
12
  while true do
13
13
  server.synchronize
14
- sleep 4
14
+ sleep 10
15
15
  end
@@ -0,0 +1,13 @@
1
+ require 'rabbitmq/cluster'
2
+
3
+ server = RabbitMQ::Cluster::Server.new(
4
+ RabbitMQManager.new('http://guest:guest@localhost:15672'),
5
+ RabbitMQ::Cluster::Etcd.new(
6
+ Etcd::Client.new(uri: ENV['ETCD_HOST'])
7
+ )
8
+ )
9
+
10
+ while true do
11
+ server.healthcheck
12
+ sleep 4
13
+ end
@@ -26,14 +26,12 @@ module RabbitMQ::Cluster
26
26
  end
27
27
 
28
28
  def synchronize
29
- join_cluster if up?
30
- return if etcd.nodes == running_nodes
29
+ remove_stopped_nodes if stopped_nodes.any?
30
+ join_cluster
31
+ end
31
32
 
32
- etcd.aquire_lock do
33
- stopped_nodes.each do |node_name|
34
- system("rabbitmqctl forget_cluster_node #{node_name}")
35
- end
36
- end
33
+ def healthcheck
34
+ register if up?
37
35
  end
38
36
 
39
37
  def name
@@ -60,17 +58,25 @@ module RabbitMQ::Cluster
60
58
  nodes(false)
61
59
  end
62
60
 
61
+ def remove_stopped_nodes
62
+ etcd.aquire_lock do
63
+ stopped_nodes.each do |node_name|
64
+ system("rabbitmqctl forget_cluster_node #{node_name}")
65
+ end
66
+ end
67
+ end
68
+
63
69
  def nodes(running)
64
70
  client.nodes.select { |n| n["running"] == running }.map { |n| n["name"] }.sort
65
71
  end
66
72
 
67
73
  def join_cluster
68
- if !clustered? && nodes_to_join.any?
74
+ if !clustered? && nodes_to_join.any? && up?
69
75
  `rabbitmqctl stop_app`
70
76
  system("rabbitmqctl join_cluster #{nodes_to_join.first}")
71
77
  `rabbitmqctl start_app`
78
+ register if up?
72
79
  end
73
- register if up?
74
80
  end
75
81
 
76
82
  def clustered?
@@ -1,5 +1,5 @@
1
1
  module RabbitMQ
2
2
  module Cluster
3
- VERSION = "0.0.9"
3
+ VERSION = "0.0.10"
4
4
  end
5
5
  end
@@ -70,7 +70,7 @@ describe RabbitMQ::Cluster::Server do
70
70
 
71
71
  context 'waiting for the server to start' do
72
72
  it 'waits until the server has started' do
73
- expect(subject).to receive(:up?).exactly(3).times.and_return(false, true)
73
+ expect(subject).to receive(:up?).exactly(2).times.and_return(false, true)
74
74
  subject.start
75
75
  end
76
76
  end
@@ -101,12 +101,6 @@ describe RabbitMQ::Cluster::Server do
101
101
  expect(subject).to_not receive(:"`")
102
102
  subject.start
103
103
  end
104
-
105
- it 'registers itself' do
106
- allow(client).to receive(:overview).and_return('cluster_name' => 'rabbit@this_node')
107
- subject.start
108
- expect(etcd.nodes).to include('rabbit@this_node')
109
- end
110
104
  end
111
105
 
112
106
  it 'tries to join the cluster' do
@@ -183,13 +177,6 @@ describe RabbitMQ::Cluster::Server do
183
177
  allow(client).to receive(:overview).and_return("cluster_name" => "rabbit@this_node")
184
178
  end
185
179
 
186
- context 'the node is up' do
187
- it 'registers the node' do
188
- expect(etcd).to receive(:register).with('rabbit@this_node')
189
- subject.synchronize
190
- end
191
- end
192
-
193
180
  context 'the node is not up' do
194
181
  before do
195
182
  allow(client).to receive(:aliveness_test).and_return("status" => "agghghghgh")
@@ -228,6 +215,31 @@ describe RabbitMQ::Cluster::Server do
228
215
  end
229
216
  end
230
217
 
218
+ describe '#healthcheck' do
219
+ context 'the node is up' do
220
+ before do
221
+ allow(client).to receive(:aliveness_test).and_return("status" => "ok")
222
+ allow(client).to receive(:overview).and_return("cluster_name" => "rabbit@this_node")
223
+ end
224
+
225
+ it 'registers the node' do
226
+ expect(etcd).to receive(:register).with('rabbit@this_node')
227
+ subject.healthcheck
228
+ end
229
+ end
230
+
231
+ context 'the node is down' do
232
+ before do
233
+ allow(client).to receive(:aliveness_test).and_return("status" => "i am really broken")
234
+ end
235
+
236
+ it 'registers the node' do
237
+ expect(etcd).to_not receive(:register)
238
+ subject.healthcheck
239
+ end
240
+ end
241
+ end
242
+
231
243
  end
232
244
 
233
245
  class FakeEtcd
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbitmq-cluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -112,6 +112,7 @@ email:
112
112
  - ed.robinson@reevoo.com
113
113
  executables:
114
114
  - rabbitmq-cluster
115
+ - rabbitmq-cluster-sidekick
115
116
  extensions: []
116
117
  extra_rdoc_files: []
117
118
  files:
@@ -121,6 +122,7 @@ files:
121
122
  - README.md
122
123
  - Rakefile
123
124
  - bin/rabbitmq-cluster
125
+ - bin/rabbitmq-cluster-sidekick
124
126
  - lib/rabbitmq/cluster.rb
125
127
  - lib/rabbitmq/cluster/etcd.rb
126
128
  - lib/rabbitmq/cluster/server.rb
@@ -144,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
146
  version: '0'
145
147
  segments:
146
148
  - 0
147
- hash: 4354114138756305473
149
+ hash: -240540097057601169
148
150
  required_rubygems_version: !ruby/object:Gem::Requirement
149
151
  none: false
150
152
  requirements:
@@ -153,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
155
  version: '0'
154
156
  segments:
155
157
  - 0
156
- hash: 4354114138756305473
158
+ hash: -240540097057601169
157
159
  requirements: []
158
160
  rubyforge_project:
159
161
  rubygems_version: 1.8.25