Skip to content

Commit

Permalink
implement infinite-loop guard in utils.query_registry_db()
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdunnjpl committed Jul 27, 2023
1 parent e1a4f8d commit 1b76919
Showing 1 changed file with 13 additions and 1 deletion.
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

0 comments on commit 1b76919

Please sign in to comment.