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

implement infinite-loop guard in utils.query_registry_db() #51

Merged
merged 1 commit into from
Jul 27, 2023
Merged
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
14 changes: 13 additions & 1 deletion src/pds/registrysweepers/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def query_registry_db(
total_hits = data["hits"]["total"]["value"]
log.debug(f" paging query ({served_hits} to {min(served_hits + page_size, total_hits)} of {total_hits})")

for hit in data["hits"]["hits"]:
response_hits = data["hits"]["hits"]
for hit in response_hits:
served_hits += 1

percentage_of_hits_served = int(served_hits / total_hits * 100)
Expand All @@ -150,6 +151,17 @@ def query_registry_db(

yield hit

# This is a temporary, ad-hoc guard against empty/erroneous responses which do not return non-200 status codes.
# Previously, this has cause infinite loops in production due to served_hits sticking and never reaching the
# expected total hits value.
# TODO: Remove this upon implementation of https://github.com/NASA-PDS/registry-sweepers/issues/42
hits_data_present_in_response = len(response_hits) > 0
if not hits_data_present_in_response:
log.error(
f"Response contained no hits when hits were expected. Returned data is incomplete. Response was: {data}"
)
break

more_data_exists = served_hits < data["hits"]["total"]["value"]

# TODO: Determine if the following block is actually necessary
Expand Down