Created
May 4, 2011 21:29
-
-
Save UnderpantsGnome/956075 to your computer and use it in GitHub Desktop.
DJ Queue Failed Solr calls for index and remove
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sunspot/session_proxy/silent_fail_session_proxy' | |
module Sunspot | |
module SessionProxy | |
class QueueFailureSessionProxy < Sunspot::SessionProxy::SilentFailSessionProxy | |
QUEUE_METHODS = [:index!, :index, :remove!, :remove] | |
def rescued_exception(method_name, ex, klass) | |
raise ex unless ::Rails.env.production? | |
if klass && QUEUE_METHODS.include?(method_name) | |
HoptoadNotifier.notify( | |
:error_class => "Solr Exception", | |
:error_message => "Solr Exception: #{ex.message}", | |
:parameters => { :model => klass, :method => method_name } | |
) if defined?(HoptoadNotifier) | |
klass.delay.index! if method_name.to_s.match('index') | |
klass.delay.remove_from_index! if method_name.to_s.match('remove') | |
else | |
raise ex | |
end | |
end | |
SUPPORTED_METHODS.each do |method| | |
module_eval(<<-RUBY) | |
def #{method}(*args, &block) | |
begin | |
search_session.#{method}(*args, &block) | |
rescue => ex | |
self.rescued_exception(:#{method}, ex, args.first) | |
end | |
end | |
RUBY | |
end | |
end | |
end | |
end | |
Sunspot.session = Sunspot::SessionProxy::QueueFailureSessionProxy.new(Sunspot.session) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment