in jobs/broken-site-report-ml/broken_site_report_ml/main.py [0:0]
def get_reports_classification(model, reports, retry_count=21, retry_sleep=10):
"""Get the classification for a list of reports.
Args:
model: The model to use for the classification.
reports: The dict containing reports to classify with uuid used as keys.
retry_count: The number of times to retry the request.
retry_sleep: The number of seconds to sleep between retries.
Returns:
A dictionary with the uuids as keys and classification results as values.
"""
if len(reports) == 0:
return {}
url = f"{BUGBUG_HTTP_SERVER}/{model}/predict/broken_site_report/batch"
json_response = {}
for _ in range(retry_count):
response = classification_http_request(url, reports)
# Check which reports are ready
for uuid, data in response["reports"].items():
if not data.get("ready", True):
continue
# The report is ready, add it to the json_response and pop it
# up from the current batch
reports.pop(uuid, None)
json_response[uuid] = data
if len(reports) == 0:
break
else:
time.sleep(retry_sleep)
else:
total_sleep = retry_count * retry_sleep
msg = f"Couldn't get {len(reports)} report classifications in {total_sleep} seconds, aborting" # noqa
logging.error(msg)
raise Exception(msg)
return json_response