lib/right_amqp/amqp/client.rb in right_amqp-0.3.3 vs lib/right_amqp/amqp/client.rb in right_amqp-0.5.2

- old
+ new

@@ -245,11 +245,17 @@ 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) { reconnect(true) } + EM.add_timer(@settings[:reconnect_interval] || 5) do + begin + reconnect(true) + rescue Exception => e + logger.exception("[amqp] Failed to reconnect", e, :trace) + end + end return end unless @reconnecting @deferred_status = nil @@ -263,23 +269,26 @@ 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) { reconnect(true) } + EM.add_timer(again) do + begin + reconnect(true) + rescue Exception => e + logger.exception("[amqp] Failed to reconnect", e, :trace) + end + end 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 @@ -289,17 +298,17 @@ @connection_status = blk end def failed @connection_status.call(:failed) if @connection_status - @has_failed = true + @failed = true close_connection end private def disconnected - unless @has_failed + unless @failed @connection_status.call(:disconnected) if @connection_status reconnect end end