Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the code file which had few errors in it. Path of the code file which i updated: app/workers/search_index_add_worker.rb #9465

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions app/workers/search_index_add_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@ def perform(class_name, id)
@class_name = class_name
@id = id

if searchable_instance.nil?
logger.warn("SearchIndexAddWorker: Could not find #{class_name} with id #{id} (#{Time.zone.now.utc}).")
elsif !searchable_instance.can_index_in_search?
logger.warn("SearchIndexAddWorker: Was asked to index #{class_name} with id #{id}, but it was unindexable (#{Time.zone.now.utc}).")
searchable_instance = find_searchable_instance
return unless searchable_instance

if searchable_instance.can_index_in_search?
add_to_search_index(searchable_instance)
else
index = Whitehall::SearchIndex.for(searchable_instance.search_api_index, logger:)
index.add searchable_instance.search_index
logger.warn("SearchIndexAddWorker: Was asked to index #{class_name} with id #{id}, but it was unindexable (#{Time.zone.now.utc}).")
end
rescue StandardError => e
logger.error("SearchIndexAddWorker: Error adding #{class_name} with id #{id} to search index: #{e.message}")
end

private

def searchable_instance
@searchable_instance ||= searchable_class.find_by(id:)
def find_searchable_instance
searchable_class.find_by(id:)
rescue StandardError => e
logger.error("SearchIndexAddWorker: Error finding #{class_name} with id #{id}: #{e.message}")
nil
end

def add_to_search_index(searchable_instance)
index = Whitehall::SearchIndex.for(searchable_instance.search_api_index, logger:)
index.add searchable_instance.search_index
rescue StandardError => e
logger.error("SearchIndexAddWorker: Error adding #{class_name} with id #{id} to search index: #{e.message}")
end

def searchable_class
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ en:
fa: Persian
fi: Finnish
fr: French
gd: Irish
ga: Irish
gu: Gujarati
he: Hebrew
hi: Hindi
Expand Down