rabbitmq-cluster 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,38 +11,56 @@ module RabbitMQ::Cluster
11
11
  end
12
12
 
13
13
  def aquire_lock
14
- sleep 1 until lock = client.update('/rabbitmq/lock', true, false)
15
- yield if lock
14
+ with_retry do
15
+ sleep 1 until lock = client.update('/rabbitmq/lock', true, false)
16
+ end
17
+ yield
16
18
  ensure
17
19
  client.update('/rabbitmq/lock', false, true)
18
20
  end
19
21
 
20
22
  def nodes
21
- (client.get('/rabbitmq/nodes') || {}).values.sort
23
+ with_retry do
24
+ (client.get('/rabbitmq/nodes') || {}).values.sort
25
+ end
22
26
  end
23
27
 
24
- def register(node_name)
25
- client.set(key_for(node_name), node_name, ttl: 10)
26
- try = 0
27
- rescue
28
- sleep 1
29
- try += 1
30
- retry if try < 10
28
+ def register(node_name, wait=nil)
29
+ with_retry(wait) do
30
+ client.set(key_for(node_name), node_name, ttl: 10)
31
+ end
31
32
  end
32
33
 
33
34
  def erlang_cookie
34
- client.get('/rabbitmq/erlang_cookie')
35
+ with_retry do
36
+ client.get('/rabbitmq/erlang_cookie')
37
+ end
35
38
  end
36
39
 
37
40
  def erlang_cookie=(erlang_cookie)
38
- client.set(
39
- '/rabbitmq/erlang_cookie',
40
- erlang_cookie
41
- )
41
+ with_retry do
42
+ client.set(
43
+ '/rabbitmq/erlang_cookie',
44
+ erlang_cookie
45
+ )
46
+ end
42
47
  end
43
48
 
44
49
  private
45
50
 
51
+ def with_retry(wait = nil)
52
+ wait ||= 1
53
+ try = 0
54
+ begin
55
+ yield
56
+ rescue
57
+ sleep wait
58
+ try += 1
59
+ retry if try < 10
60
+ raise
61
+ end
62
+ end
63
+
46
64
  def key_for(node_name)
47
65
  "/rabbitmq/nodes/#{node_name}"
48
66
  end
@@ -1,5 +1,5 @@
1
1
  module RabbitMQ
2
2
  module Cluster
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  end
@@ -33,6 +33,17 @@ describe RabbitMQ::Cluster::Etcd do
33
33
  )
34
34
  subject.register(nodename)
35
35
  end
36
+
37
+ context 'somthing is wrong with etcd backend' do
38
+ before do
39
+ allow(subject).to receive(:wait).and_return(0.001)
40
+ end
41
+
42
+ it 'retry 10 times' do
43
+ expect(etcd_client).to receive(:set).exactly(10).times.and_raise
44
+ expect { subject.register('foo', 0.0001) }.to raise_error
45
+ end
46
+ end
36
47
  end
37
48
 
38
49
 
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.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -144,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  segments:
146
146
  - 0
147
- hash: -1773046111875940533
147
+ hash: 4354114138756305473
148
148
  required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  version: '0'
154
154
  segments:
155
155
  - 0
156
- hash: -1773046111875940533
156
+ hash: 4354114138756305473
157
157
  requirements: []
158
158
  rubyforge_project:
159
159
  rubygems_version: 1.8.25