[deploy] Ignore Search::Errors::Transport::NotFound error when Removing Reactions (#7567)

This commit is contained in:
Molly Struve 2020-04-28 10:56:25 -05:00 committed by GitHub
parent e94e76db04
commit af673221bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View file

@ -8,6 +8,8 @@ module Search
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

View file

@ -6,6 +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
end
end
end

View file

@ -2,13 +2,27 @@ require "rails_helper"
RSpec.describe Search::RemoveFromElasticsearchIndexWorker, type: :worker do
let(:worker) { subject }
let(:search_class) { Search::Tag }
include_examples "#enqueues_on_correct_queue", "medium_priority", ["SearchClass", 1]
it "deletes document for given search class" do
search_class = Search::Tag
allow(search_class).to receive(:delete_document)
described_class.new.perform(search_class.to_s, 1)
expect(search_class).to have_received(:delete_document).with(1)
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(
Search::Errors::Transport::NotFound,
)
end
end
end