in bot/code_coverage_bot/artifacts.py [0:0]
def download_all(self) -> None:
os.makedirs(self.parent_dir, exist_ok=True)
logger.info("Downloading artifacts from {} tasks".format(len(self.test_tasks)))
for test_task in self.test_tasks:
status = test_task["status"]["state"]
task_id = test_task["status"]["taskId"]
if status in taskcluster.FINISHED_STATUSES:
continue
while True:
# refresh the status information
task_status = taskcluster.get_task_status(task_id)
status = task_status["status"]["state"]
assert (
status in taskcluster.ALL_STATUSES
), "State '{}' not recognized".format(status)
if status in taskcluster.FINISHED_STATUSES:
# Update the task status, as we will use it to compare statuses later.
test_task["status"]["state"] = status
break
logger.info(f"Waiting for task {task_id} to finish...")
time.sleep(60)
# Choose best tasks to download (e.g. 'completed' is better than 'failed')
download_tasks = {}
for test_task in self.test_tasks:
status = test_task["status"]["state"]
assert (
status in taskcluster.FINISHED_STATUSES
), "State '{}' not recognized".format(status)
chunk_name = taskcluster.get_chunk(test_task["task"])
platform_name = taskcluster.get_platform(test_task["task"])
if any(to_ignore in chunk_name for to_ignore in SUITES_TO_IGNORE):
continue
if (chunk_name, platform_name) not in download_tasks:
# If the chunk hasn't been downloaded before, this is obviously the best task
# to download it from.
download_tasks[(chunk_name, platform_name)] = test_task
else:
# Otherwise, compare the status of this task with the previously selected task.
prev_task = download_tasks[(chunk_name, platform_name)]
if STATUS_VALUE[status] > STATUS_VALUE[prev_task["status"]["state"]]:
download_tasks[(chunk_name, platform_name)] = test_task
with ThreadPoolExecutorResult() as executor:
futures = [
executor.submit(self.download, test_task)
for test_task in download_tasks.values()
]
for future in concurrent.futures.as_completed(futures):
exc = future.exception()
if exc is not None:
logger.error("Exception while downloading artifacts", exception=exc)
for f in futures:
f.cancel()
logger.info("Code coverage artifacts downloaded")