Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry failed updates at least once after a 500ms delay. #198

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions sunspot/lib/sunspot/session_proxy/retry_fail_session_proxy.rb
@@ -0,0 +1,45 @@
require File.join(File.dirname(__FILE__), 'abstract_session_proxy')

module Sunspot
module SessionProxy
class RetryFailSessionProxy < AbstractSessionProxy

attr_reader :search_session

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
end

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

SUPPORTED_METHODS = [
: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
]

SUPPORTED_METHODS.each do |method|
module_eval(<<-RUBY)
def #{method}(*args, &block)
retry_count = 1
begin
search_session.#{method}(*args, &block)
rescue => e
sleep 0.5
self.rescued_exception(:#{method}, e)
retry if (retry_count -= 1) >= 0
end
end
RUBY
end

end
end
end