Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
DJ Queue Failed Solr calls for index and remove
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