Class: Gnip::GnipStream::ErrorReconnect

Inherits:
Object
  • Object
show all
Defined in:
lib/gnip/gnip-stream/error_reconnect.rb

Instance Method Summary collapse

Constructor Details

#initialize(source_class, method_name) ⇒ ErrorReconnect

Returns a new instance of ErrorReconnect.



6
7
8
9
10
# File 'lib/gnip/gnip-stream/error_reconnect.rb', line 6

def initialize(source_class, method_name)
  @source_class = source_class
  @method_name = method_name
  @reconnect_attempts = 0
end

Instance Method Details

#attempt_to_reconnect(error_message) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/gnip/gnip-stream/error_reconnect.rb', line 12

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

#reconnect_failed_raise_errorObject

Raises:

  • (@error_message)


23
24
25
# File 'lib/gnip/gnip-stream/error_reconnect.rb', line 23

def reconnect_failed_raise_error
  raise @error_message
end