Class: Sunspot::SessionProxy::Retry5xxSessionProxy::RetryHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/sunspot/session_proxy/retry_5xx_session_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search_session) ⇒ RetryHandler

Returns a new instance of RetryHandler.



10
11
12
# File 'lib/sunspot/session_proxy/retry_5xx_session_proxy.rb', line 10

def initialize(search_session)
  @search_session = search_session
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sunspot/session_proxy/retry_5xx_session_proxy.rb', line 14

def method_missing(m, *args, &block)
  retry_count = 1
  begin
    search_session.send(m, *args, &block)
  rescue Errno::ECONNRESET => e
    if retry_count > 0
      $stderr.puts "Error - #{e.message[/^.*$/]} - retrying..."
      retry_count -= 1
      retry
    else
      $stderr.puts "Error - #{e.message[/^.*$/]} - ignoring..."
    end
  rescue RSolr::Error::Http => e
    if (500..599).include?(e.response[:status].to_i)
      if retry_count > 0
        $stderr.puts "Error - #{e.message[/^.*$/]} - retrying..."
        retry_count -= 1
        retry
      else
        $stderr.puts "Error - #{e.message[/^.*$/]} - ignoring..."
        e.response
      end
    else
      raise e
    end
  end
end

Instance Attribute Details

#search_sessionObject (readonly)

Returns the value of attribute search_session.



8
9
10
# File 'lib/sunspot/session_proxy/retry_5xx_session_proxy.rb', line 8

def search_session
  @search_session
end