right_amqp 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -247,13 +247,7 @@ module AMQP
247
247
  def reconnect force = false
248
248
  if @reconnecting and not force
249
249
  # Wait after first reconnect attempt and in between each subsequent attempt
250
- EM.add_timer(@settings[:reconnect_interval] || 5) do
251
- begin
252
- reconnect(true)
253
- rescue Exception => e
254
- logger.exception("[amqp] Failed to reconnect", e, :trace)
255
- end
256
- end
250
+ EM.add_timer(@settings[:reconnect_interval] || 5) { reconnect(true) }
257
251
  return
258
252
  end
259
253
 
@@ -271,13 +265,7 @@ module AMQP
271
265
  again = again.call if again.is_a?(Proc)
272
266
  if again.is_a?(Numeric)
273
267
  # Wait before making initial reconnect attempt
274
- EM.add_timer(again) do
275
- begin
276
- reconnect(true)
277
- rescue Exception => e
278
- logger.exception("[amqp] Failed to reconnect", e, :trace)
279
- end
280
- end
268
+ EM.add_timer(again) { reconnect(true) }
281
269
  return
282
270
  elsif ![nil, true].include?(again)
283
271
  raise ::AMQP::Error, "Could not interpret :reconnect_delay => #{again.inspect}; expected nil, true, or Numeric"
@@ -287,6 +275,9 @@ module AMQP
287
275
  log 'reconnecting'
288
276
  logger.info("[amqp] Attempting to reconnect to #{@settings[:identity]}")
289
277
  EM.reconnect(@settings[:host], @settings[:port], self)
278
+ rescue Exception => e
279
+ logger.exception("[amqp] Failed to reconnect", e, :trace)
280
+ failed
290
281
  end
291
282
 
292
283
  def self.connect opts = {}
@@ -300,14 +291,14 @@ module AMQP
300
291
 
301
292
  def failed
302
293
  @connection_status.call(:failed) if @connection_status
303
- @failed = true
294
+ @has_failed = true
304
295
  close_connection
305
296
  end
306
297
 
307
298
  private
308
299
 
309
300
  def disconnected
310
- unless @failed
301
+ unless @has_failed
311
302
  @connection_status.call(:disconnected) if @connection_status
312
303
  reconnect
313
304
  end
data/right_amqp.gemspec CHANGED
@@ -24,8 +24,8 @@ require 'rubygems'
24
24
 
25
25
  Gem::Specification.new do |spec|
26
26
  spec.name = 'right_amqp'
27
- spec.version = '0.3.2'
28
- spec.date = '2012-10-04'
27
+ spec.version = '0.3.3'
28
+ spec.date = '2012-10-30'
29
29
  spec.authors = ['Lee Kirchhoff']
30
30
  spec.email = 'lee@rightscale.com'
31
31
  spec.homepage = 'https://github.com/rightscale/right_amqp'
@@ -33,7 +33,7 @@ describe AMQP::Client do
33
33
  class SUT
34
34
  include AMQP::Client
35
35
 
36
- attr_accessor :reconnecting, :settings, :channels
36
+ attr_accessor :reconnecting, :settings, :channels, :has_failed
37
37
  end
38
38
 
39
39
  before(:each) do
@@ -88,7 +88,7 @@ describe AMQP::Client do
88
88
  end
89
89
  end
90
90
 
91
- context 'with a :reconnect_interval of 5 seconds' do
91
+ context 'with a :reconnect_interval of 5 seconds' do
92
92
  it 'should schedule reconnect attempts on a 5s interval' do
93
93
  @sut.reconnecting = true
94
94
  @sut.settings[:reconnect_delay] = 15
@@ -101,6 +101,17 @@ describe AMQP::Client do
101
101
  end
102
102
  end
103
103
 
104
+ context 'with a reconnect failure' do
105
+ it 'should fail the connection' do
106
+ @logger.should_receive(:error).with(/Failed to reconnect/).once
107
+ flexmock(EM).should_receive(:reconnect).and_raise(Exception).once
108
+ flexmock(@sut).should_receive(:close_connection).once
109
+
110
+ @sut.reconnect()
111
+ @sut.has_failed.should be_true
112
+ end
113
+ end
114
+
104
115
  end
105
116
 
106
117
  context "heartbeat" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: right_amqp
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.2
5
+ version: 0.3.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Lee Kirchhoff
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-10-04 00:00:00 Z
13
+ date: 2012-10-30 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: right_support
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
- hash: 60400910479135744
111
+ hash: 3853339962188716916
112
112
  segments:
113
113
  - 0
114
114
  version: "0"