Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UnderpantsGnome/956075 to your computer and use it in GitHub Desktop.
Save UnderpantsGnome/956075 to your computer and use it in GitHub Desktop.
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