1515import time
1616from operator import xor
1717from threading import Thread
18+ from enum import Enum
1819
1920import werkzeug .exceptions
2021from hubmap_sdk import EntitySdk , sdk_helper
@@ -484,8 +485,11 @@ def _validate_token_if_auth_header_exists(request):
484485
485486
486487# Use the Flask request.args MultiDict to see if 'reindex' is a URL parameter passed in with the
487- # request and if it indicates reindexing should be supressed . Default to reindexing in all other cases.
488+ # request and if it indicates reindexing should be suppressed . Default to reindexing in all other cases.
488489def _suppress_reindex () -> bool :
490+ # N.B. This logic should be the same as that used by
491+ # entity-api schema_manager.py suppress_reindex()
492+ # https://github.com/hubmapconsortium/entity-api/blob/main/src/schema/schema_manager.py
489493 if 'reindex' not in request .args :
490494 return False
491495 reindex_str = request .args .get ('reindex' ).lower ()
@@ -496,6 +500,49 @@ def _suppress_reindex() -> bool:
496500 raise Exception (f"The value of the 'reindex' parameter must be True or False (case-insensitive)."
497501 f" '{ request .args .get ('reindex' )} ' is not recognized." )
498502
503+ """
504+ See if 'reindex-priority' is a URL parameter passed in with the request, if it is valid, and
505+ if it is compatible with the calculated _suppress_reindex() result. Default to 1 when not specified.
506+
507+ Parameters
508+ ----------
509+ request_args:
510+ The Flask request.args passed in from application request
511+
512+ calc_suppress_reindex:
513+ The value returned from the suppress_reindex() method, if previously called.
514+ Returns
515+ -------
516+ int value from the enumeration ReindexPriorityLevelEnum
517+ """
518+ def _get_reindex_priority (calc_suppress_reindex :bool ) -> int :
519+ # N.B. This logic should be the same as that used by
520+ # ingest-api app.py _get_reindex_priority()
521+ # https://github.com/hubmapconsortium/ingest-api/blob/main/src/app.py
522+
523+ # Define an enumeration of re-index priority level types.
524+ # N.B. This is the same values maintained in entity-api schema_constants.py, which
525+ # must be the same levels defined for the enqueue() method at
526+ # https://github.com/x-atlas-consortia/jobq/blob/main/src/atlas_consortia_jobq/queue.py
527+ class ReindexPriorityLevelEnum (Enum ):
528+ HIGH = 1
529+ MEDIUM = 2
530+ LOW = 3
531+
532+ if calc_suppress_reindex and 'reindex-priority' in request .args :
533+ raise Exception ("Specifying a re-index priority is incompatible with suppressing re-indexing." )
534+ if 'reindex-priority' not in request .args :
535+ return ReindexPriorityLevelEnum .HIGH .value
536+ try :
537+ priority_int = int (request .args .get ('reindex-priority' ))
538+ except ValueError as ve :
539+ raise Exception ("The value of the 'reindex-priority' parameter must be an integer." )
540+ if priority_int not in ReindexPriorityLevelEnum :
541+ raise Exception (f"The value of the 'reindex-priority' parameter must be"
542+ f" greater than or equal to { ReindexPriorityLevelEnum .HIGH .value } (high priority)"
543+ f" and less than or equal to { ReindexPriorityLevelEnum .LOW .value } (low priority)." )
544+ return priority_int
545+
499546####################################################################################################
500547## Ingest API Endpoints
501548####################################################################################################
@@ -908,11 +955,13 @@ def create_datastage():
908955
909956 # Check URL parameters before proceeding to any CRUD operations, halting on validation failures.
910957 #
911- # Check if re-indexing is to be suppressed after entity creation.
912958 try :
959+ # Check if re-indexing is to be suppressed after entity creation.
913960 suppress_reindex = _suppress_reindex ()
961+ # Determine valid re-indexing priority using Request parameters.
962+ reindex_priority = _get_reindex_priority (calc_suppress_reindex = suppress_reindex )
914963 except Exception as e :
915- bad_request_error (str ( e ) )
964+ bad_request_error (e . args [ 0 ] )
916965
917966 post_url = f"{ commons_file_helper .ensureTrailingSlashURL (app .config ['ENTITY_WEBSERVICE_URL' ])} " \
918967 f"entities/{ entity_type } " \
@@ -976,11 +1025,13 @@ def multiple_components():
9761025
9771026 # Check URL parameters before proceeding to any CRUD operations, halting on validation failures.
9781027 #
979- # Check if re-indexing is to be suppressed after entity creation.
9801028 try :
1029+ # Check if re-indexing is to be suppressed after entity creation.
9811030 suppress_reindex = _suppress_reindex ()
1031+ # Determine valid re-indexing priority using Request parameters.
1032+ reindex_priority = _get_reindex_priority (calc_suppress_reindex = suppress_reindex )
9821033 except Exception as e :
983- bad_request_error (e )
1034+ bad_request_error (e . args [ 0 ] )
9841035
9851036 post_url = f"{ commons_file_helper .ensureTrailingSlashURL (app .config ['ENTITY_WEBSERVICE_URL' ])} " \
9861037 f"datasets/components" \
@@ -1636,11 +1687,13 @@ def submit_dataset(uuid):
16361687
16371688 # Check URL parameters before proceeding to any CRUD operations, halting on validation failures.
16381689 #
1639- # Check if re-indexing is to be suppressed after entity creation.
16401690 try :
1691+ # Check if re-indexing is to be suppressed after entity creation.
16411692 suppress_reindex = _suppress_reindex ()
1693+ # Determine valid re-indexing priority using Request parameters.
1694+ reindex_priority = _get_reindex_priority (calc_suppress_reindex = suppress_reindex )
16421695 except Exception as e :
1643- bad_request_error (e )
1696+ bad_request_error (e . args [ 0 ] )
16441697
16451698 try :
16461699 put_url = f"{ commons_file_helper .ensureTrailingSlashURL (app .config ['ENTITY_WEBSERVICE_URL' ])} " \
0 commit comments