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

Update indexing logic to handle for unknown file_import tasks #2956

Merged
38 changes: 25 additions & 13 deletions refinery/data_set_manager/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,28 @@ def prepare(self, node):


def _get_download_url_or_import_state(file_store_item):
download_url = constants.NOT_AVAILABLE
if file_store_item is not None:
download_url = file_store_item.get_datafile_url()
if download_url is None:
import_state = file_store_item.get_import_status()
if import_state in celery.states.READY_STATES:
# Here we've reached a celery "READY STATE" without a valid
# download url
import_state = constants.NOT_AVAILABLE
else:
import_state = celery.states.PENDING
return import_state
return download_url
"""
Discerns the download url or file import state for a given FileStoreItem
:param file_store_item: A FileStoreItem instance
:returns <String>:
- a valid url pointing to the FileStoreItem's datafile
- constants.NOT_AVAILABLE
- celery.states.PENDING
"""
if file_store_item is None:
return constants.NOT_AVAILABLE

download_url = file_store_item.get_datafile_url()
if download_url:
return download_url

# "PENDING" if an import_task_id doesn't exist and
# there is no valid download_url
if not file_store_item.import_task_id:
return celery.states.PENDING

# "N/A" if the import_state is in a "READY_STATE" or "PENDING" with an
# import_task_id and without a valid download_url
import_state = file_store_item.get_import_status()
if import_state in {celery.states.PENDING} | celery.states.READY_STATES:
return constants.NOT_AVAILABLE
2 changes: 1 addition & 1 deletion refinery/data_set_manager/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ def test_prepare_node_pending_yet_existing_file_import_task(self):
return_value=PENDING):
self._assert_node_index_prepared_correctly(
self._prepare_node_index(self.node),
expected_download_url=PENDING
expected_download_url=constants.NOT_AVAILABLE
)

def test_prepare_node_pending_non_existent_file_import_task(self):
Expand Down