lib/right_amqp/amqp/client.rb in right_amqp-0.5.2 vs lib/right_amqp/amqp/client.rb in right_amqp-0.6.0
- old
+ new
@@ -245,17 +245,11 @@
end
def reconnect force = false
if @reconnecting and not force
# Wait after first reconnect attempt and in between each subsequent attempt
- EM.add_timer(@settings[:reconnect_interval] || 5) do
- begin
- reconnect(true)
- rescue Exception => e
- logger.exception("[amqp] Failed to reconnect", e, :trace)
- end
- end
+ EM.add_timer(@settings[:reconnect_interval] || 5) { reconnect(true) }
return
end
unless @reconnecting
@deferred_status = nil
@@ -269,26 +263,23 @@
again = @settings[:reconnect_delay]
again = again.call if again.is_a?(Proc)
if again.is_a?(Numeric)
# Wait before making initial reconnect attempt
- EM.add_timer(again) do
- begin
- reconnect(true)
- rescue Exception => e
- logger.exception("[amqp] Failed to reconnect", e, :trace)
- end
- end
+ EM.add_timer(again) { reconnect(true) }
return
elsif ![nil, true].include?(again)
raise ::AMQP::Error, "Could not interpret :reconnect_delay => #{again.inspect}; expected nil, true, or Numeric"
end
end
log 'reconnecting'
logger.info("[amqp] Attempting to reconnect to #{@settings[:identity]}")
EM.reconnect(@settings[:host], @settings[:port], self)
+ rescue Exception => e
+ logger.exception("[amqp] Failed to reconnect", e, :trace)
+ failed
end
def self.connect opts = {}
opts = AMQP.settings.merge(opts)
EM.connect opts[:host], opts[:port], self, opts
@@ -298,17 +289,17 @@
@connection_status = blk
end
def failed
@connection_status.call(:failed) if @connection_status
- @failed = true
+ @has_failed = true
close_connection
end
private
def disconnected
- unless @failed
+ unless @has_failed
@connection_status.call(:disconnected) if @connection_status
reconnect
end
end