Sha256: 9bdfda6e3786589b6b5a902c01f85e3af606b09343ab7ef5d8d9bded9ac2fa04

Contents?: true

Size: 1.99 KB

Versions: 14

Compression:

Stored size: 1.99 KB

Contents

require File.join(File.dirname(__FILE__), 'abstract_session_proxy')

module Sunspot
  module SessionProxy
    class Retry5xxSessionProxy < AbstractSessionProxy

      class RetryHandler
        attr_reader :search_session

        def initialize(search_session)
          @search_session = search_session
        end

        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
      end

      attr_reader :search_session
      attr_reader :retry_handler

      delegate :new_search, :search, :config,
                :new_more_like_this, :more_like_this,
                :delete_dirty, :delete_dirty?,
                :to => :search_session

      def initialize(search_session = Sunspot.session)
        @search_session = search_session
        @retry_handler = RetryHandler.new(search_session)
      end

      def rescued_exception(method, e)
        $stderr.puts("Exception in #{method}: #{e.message}")
      end

      delegate :batch, :commit, :commit_if_dirty, :commit_if_delete_dirty,
        :dirty?, :index!, :index, :optimize, :remove!, :remove, :remove_all!,
        :remove_all, :remove_by_id!, :remove_by_id,
        :to => :retry_handler

    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
sunspot-2.2.0 lib/sunspot/session_proxy/retry_5xx_session_proxy.rb
sunspot-2.1.1 lib/sunspot/session_proxy/retry_5xx_session_proxy.rb
sunspot-2.1.0 lib/sunspot/session_proxy/retry_5xx_session_proxy.rb
sunspot-2.0.0 lib/sunspot/session_proxy/retry_5xx_session_proxy.rb
sunspot-2.0.0.pre.130115 lib/sunspot/session_proxy/retry_5xx_session_proxy.rb
sunspot-2.0.0.pre.120925 lib/sunspot/session_proxy/retry_5xx_session_proxy.rb
sunspot_solr-2.0.0.pre.120924 sunspot/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb
sunspot_rails-2.0.0.pre.120924 sunspot/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb
sunspot-2.0.0.pre.120924 sunspot/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb
sunspot-2.0.0.pre.120720 lib/sunspot/session_proxy/retry_5xx_session_proxy.rb
sunspot-1.3.3 lib/sunspot/session_proxy/retry_5xx_session_proxy.rb
sunspot-1.3.2 lib/sunspot/session_proxy/retry_5xx_session_proxy.rb
sunspot-2.0.0.pre.120417 lib/sunspot/session_proxy/retry_5xx_session_proxy.rb
sunspot-2.0.0.pre.120415 lib/sunspot/session_proxy/retry_5xx_session_proxy.rb