Commit ac80d7e35f6f754ff5545d51828b6a41f8223346
1 parent
64e35004
Exists in
master
and in
19 other branches
Only rescue certain errors when reindexing - #802
Showing
5 changed files
with
22 additions
and
2 deletions
Show diff stats
Gemfile
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
test/gemfiles/nobrainer.gemfile
test/test_helper.rb
... | ... | @@ -18,7 +18,11 @@ puts "Running against Elasticsearch #{Searchkick.server_version}" |
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? | ... | ... |