[deploy] Ignore Unfound Elasticsearch Docs and Records (#8225)
This commit is contained in:
parent
948e984ef3
commit
139c7fc686
4 changed files with 12 additions and 28 deletions
|
|
@ -5,14 +5,8 @@ module Search
|
|||
sidekiq_options queue: :high_priority, lock: :until_executing
|
||||
|
||||
def perform(object_class, id)
|
||||
object = object_class.constantize.find(id)
|
||||
object.index_to_elasticsearch_inline
|
||||
rescue ActiveRecord::RecordNotFound => e
|
||||
# Reactions can often be destroyed before this indexing job can execute
|
||||
# so we ignore this error
|
||||
return if object_class == "Reaction"
|
||||
|
||||
raise e
|
||||
object = object_class.constantize.find_by(id: id)
|
||||
object&.index_to_elasticsearch_inline
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ module Search
|
|||
|
||||
def perform(search_class, id)
|
||||
search_class.safe_constantize.delete_document(id)
|
||||
rescue Search::Errors::Transport::NotFound => e
|
||||
# Reactions are often destroyed before the indexing job can execute
|
||||
# so we ignore this error when trying to remove them
|
||||
return if search_class == "Search::Reaction"
|
||||
|
||||
raise e
|
||||
rescue Search::Errors::Transport::NotFound
|
||||
# Often race conditions cause us never to index a document and
|
||||
# we end up with an error when trying to remove it. Because
|
||||
# we have count checks that run every hour to track the counts in
|
||||
# Elasticsearch and db to ensure they match we can ignore this error
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,10 +5,6 @@ RSpec.describe Search::IndexWorker, type: :worker, elasticsearch: "Tag" do
|
|||
|
||||
include_examples "#enqueues_on_correct_queue", "high_priority", ["Tag", 1]
|
||||
|
||||
it "raises an error if record is not found" do
|
||||
expect { worker.perform("Tag", 1234) }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it "indexes document" do
|
||||
tag = FactoryBot.create(:tag)
|
||||
expect { tag.elasticsearch_doc }.to raise_error(Search::Errors::Transport::NotFound)
|
||||
|
|
@ -17,7 +13,7 @@ RSpec.describe Search::IndexWorker, type: :worker, elasticsearch: "Tag" do
|
|||
expect(tag.elasticsearch_doc.dig("_source", "id")).to eql(tag.id)
|
||||
end
|
||||
|
||||
it "does not raise an error if Reaction record is not found" do
|
||||
expect { worker.perform("Reaction", 1234) }.not_to raise_error(ActiveRecord::RecordNotFound)
|
||||
it "does not raise an error if record is not found" do
|
||||
expect { worker.perform("Tag", 1234) }.not_to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,14 +13,8 @@ RSpec.describe Search::RemoveFromIndexWorker, type: :worker do
|
|||
end
|
||||
|
||||
context "when document is not found" do
|
||||
it "raises error" do
|
||||
expect { described_class.new.perform(search_class.to_s, 1) }.to raise_error(
|
||||
Search::Errors::Transport::NotFound,
|
||||
)
|
||||
end
|
||||
|
||||
it "does not raise error if removing a Reaction" do
|
||||
expect { described_class.new.perform("Search::Reaction", 1) }.not_to raise_error(
|
||||
it "does not raise error" do
|
||||
expect { described_class.new.perform(search_class.to_s, 1) }.not_to raise_error(
|
||||
Search::Errors::Transport::NotFound,
|
||||
)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue