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

Libpitt/enumerate thread #60

Draft
wants to merge 3 commits into
base: dev-integrate
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 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
18 changes: 16 additions & 2 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,16 +705,30 @@ def reindex_all(self):

try:
translator = self.init_translator(token)
threading.Thread(target=translator.translate_all, args=[]).start()
job_name = 'reindex_all'
if self._is_job_thread_running(job_name) is False:
threading.Thread(target=translator.translate_all, args=[], name=job_name).start()
logger.info('Started live reindex all')
else:
logger.info('Could not start live reindex all. Thread already running.')
return 'Request of live reindex all documents not accepted', 409
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@libpitt I would change the return to add that the method is already running.

"Request of live reindex all documents not accepted. Reindex all process already running" - something like that


logger.info('Started live reindex all')
except Exception as e:
logger.exception(e)

internal_server_error(e)

return 'Request of live reindex all documents accepted', 202

def _is_job_thread_running(self, job_name):
is_running = False
for th in threading.enumerate():
if th.name == job_name:
is_running = True
break

return is_running

def _get_index_mappings(self, composite_index):
# get URL for the composite index specified.
configured_base_url = self.INDICES['indices'][composite_index]['elasticsearch']['url'].strip('/')
Expand Down
21 changes: 18 additions & 3 deletions src/opensearch_helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,26 @@ def get_uuids_from_es(index, es_url):

def execute_opensearch_query(query_against, request, index, es_url, query=None, request_params=None):
supported_query_against = ['_search', '_count', '_mget']
supported_endpoints_with_id = ['_update']
supported_endpoints = supported_query_against + supported_endpoints_with_id
separator = ','

if query_against not in supported_query_against:
bad_request_error(
f"Query against '{query_against}' is not supported by Search API. Use one of the following: {separator.join(supported_query_against)}")
# If query_against has a / in it, assume a 32 character identifier after the / is okay, but
# verify the endpoint_base name before the / is in supported_query_against
if '/' in query_against:
endpoint_elements = query_against.split(sep='/'
,maxsplit=1)
# For an internal function like this, assume the 32 character part after the / is
# a UUID without verifying the format, and allow it through.
if endpoint_elements[0] not in supported_endpoints_with_id \
or len(endpoint_elements[1]) != 32:
bad_request_error(f"Query of endpoint '{endpoint_elements[0]}'"
f" with identifier '{endpoint_elements[1]}'"
" is not supported by Search API."
f" Supported endoints are: {separator.join(supported_endpoints)}")
elif query_against not in supported_query_against:
bad_request_error( f"Query against '{query_against}' is not supported by Search API."
f" Use one of the following: {separator.join(supported_endpoints)}")

# Determine the target real index in Elasticsearch to be searched against
# index = get_target_index(request, index_without_prefix)
Expand Down