Skip to content

Commit

Permalink
Retry after 60 seconds instead of throwing error
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusroemer committed Sep 23, 2024
1 parent 3b94ef0 commit b75314d
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions ingest/scripts/call_loculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,25 +312,29 @@ def get_submitted(config: Config):
"statusesFilter": [],
}

logger.info("Getting previously submitted sequences")
while True:
logger.info("Getting previously submitted sequences")

response = make_request(HTTPMethod.GET, url, config, params=params)
expected_record_count = int(response.headers["x-total-records"])
response = make_request(HTTPMethod.GET, url, config, params=params)
expected_record_count = int(response.headers["x-total-records"])

entries: list[dict[str, Any]] = []
try:
entries = list(jsonlines.Reader(response.iter_lines()).iter())
except jsonlines.Error as err:
response_summary = response.text
max_error_length = 100
if len(response_summary) > max_error_length:
response_summary = response_summary[:50] + "\n[..]\n" + response_summary[-50:]
logger.error(f"Error decoding JSON from /get-original-metadata: {response_summary}")
raise ValueError from err

if len(entries) != expected_record_count:
logger.error("Got incomplete original metadata stream")
raise ValueError
entries: list[dict[str, Any]] = []
try:
entries = list(jsonlines.Reader(response.iter_lines()).iter())
except jsonlines.Error as err:
response_summary = response.text
max_error_length = 100
if len(response_summary) > max_error_length:
response_summary = response_summary[:50] + "\n[..]\n" + response_summary[-50:]
logger.error(f"Error decoding JSON from /get-original-metadata: {response_summary}")
raise ValueError from err

if len(entries) == expected_record_count:
f"Got {len(entries)} records as expected"
break
logger.error(f"Got incomplete original metadata stream: expected {len(entries)}"
f"records but got {expected_record_count}. Retrying after 60 seconds.")
sleep(60)

# Initialize the dictionary to store results
submitted_dict: dict[str, dict[str, str | list]] = {}
Expand Down

0 comments on commit b75314d

Please sign in to comment.