Commit ac80d7e35f6f754ff5545d51828b6a41f8223346

Authored by Andrew Kane
1 parent 64e35004

Only rescue certain errors when reindexing - #802

Gemfile
... ... @@ -7,3 +7,4 @@ gem "sqlite3"
7 7 gem "activerecord", "~> 5.0.0"
8 8 gem "gemoji-parser"
9 9 gem "typhoeus"
  10 +gem "activejob"
... ...
lib/searchkick/reindex_v2_job.rb
1 1 module Searchkick
2 2 class ReindexV2Job < ActiveJob::Base
  3 + RECORD_NOT_FOUND_CLASSES = [
  4 + "ActiveRecord::RecordNotFound",
  5 + "Mongoid::Errors::DocumentNotFound",
  6 + "NoBrainer::Error::DocumentNotFound"
  7 + ]
  8 +
3 9 queue_as :searchkick
4 10  
5 11 def perform(klass, id)
6 12 model = klass.constantize
7   - record = model.find(id) rescue nil # TODO fix lazy coding
  13 + record =
  14 + begin
  15 + model.find(id)
  16 + rescue => e
  17 + raise e unless RECORD_NOT_FOUND_CLASSES.include?(e.class.name)
  18 + nil
  19 + end
  20 +
8 21 index = model.searchkick_index
9 22 if !record || !record.should_index?
10 23 # hacky
... ...
test/gemfiles/mongoid6.gemfile
... ... @@ -4,3 +4,4 @@ source &#39;https://rubygems.org&#39;
4 4 gemspec path: "../../"
5 5  
6 6 gem "mongoid", "~> 6.0.0"
  7 +gem "activejob"
... ...
test/gemfiles/nobrainer.gemfile
... ... @@ -4,3 +4,4 @@ source &#39;https://rubygems.org&#39;
4 4 gemspec path: "../../"
5 5  
6 6 gem "nobrainer", ">= 0.21.0"
  7 +gem "activejob"
... ...
test/test_helper.rb
... ... @@ -18,7 +18,11 @@ puts &quot;Running against Elasticsearch #{Searchkick.server_version}&quot;
18 18  
19 19 I18n.config.enforce_available_locales = true
20 20  
21   -ActiveJob::Base.logger = nil if defined?(ActiveJob)
  21 +if defined?(ActiveJob)
  22 + ActiveJob::Base.logger = nil
  23 + ActiveJob::Base.queue_adapter = :inline
  24 +end
  25 +
22 26 ActiveSupport::LogSubscriber.logger = Logger.new(STDOUT) if ENV["NOTIFICATIONS"]
23 27  
24 28 def elasticsearch_below50?
... ...