Sha256: b55e7256aa882bf5e681e0b8c42139d7a7e836ce0ded83b1381611857b1bd57a

Contents?: true

Size: 617 Bytes

Versions: 11

Compression:

Stored size: 617 Bytes

Contents

module Gnip
  module GnipStream
    
    class ErrorReconnect
    
      def initialize(source_class, method_name)
        @source_class = source_class
        @method_name = method_name
        @reconnect_attempts = 0
      end

      def attempt_to_reconnect(error_message)
        @error_message = error_message
        if @reconnect_attempts < 5
          @reconnect_attempts +=1
          sleep(2)
          @source_class.send(@method_name)
        else
          reconnect_failed_raise_error
        end
      end

      def reconnect_failed_raise_error
        raise @error_message
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
gnip-client-0.2.8 lib/gnip/gnip-stream/error_reconnect.rb
gnip-client-0.2.7 lib/gnip/gnip-stream/error_reconnect.rb
gnip-client-0.2.6 lib/gnip/gnip-stream/error_reconnect.rb
gnip-client-0.2.5 lib/gnip/gnip-stream/error_reconnect.rb
gnip-client-0.2.4 lib/gnip/gnip-stream/error_reconnect.rb
gnip-client-0.2.3 lib/gnip/gnip-stream/error_reconnect.rb
gnip-client-0.2.2 lib/gnip/gnip-stream/error_reconnect.rb
gnip-client-0.2.1 lib/gnip/gnip-stream/error_reconnect.rb
gnip-client-0.2.0 lib/gnip/gnip-stream/error_reconnect.rb
gnip-client-0.1.9 lib/gnip/gnip-stream/error_reconnect.rb
gnip-client-0.1.8 lib/gnip/gnip-stream/error_reconnect.rb