From fc3aa839c9754e0444073eefbc4661aca4357a8b Mon Sep 17 00:00:00 2001 From: "Andres D. Molins" Date: Tue, 23 Jan 2024 18:33:00 +0100 Subject: [PATCH] Fix: Applied PR review fixes. --- deployment/prepare_vrf_vms.py | 19 +++++-------------- src/aleph_vrf/coordinator/vrf.py | 12 ++++++------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/deployment/prepare_vrf_vms.py b/deployment/prepare_vrf_vms.py index cba5f63..7acedbc 100644 --- a/deployment/prepare_vrf_vms.py +++ b/deployment/prepare_vrf_vms.py @@ -25,13 +25,8 @@ async def prepare_executor_nodes(executor_item_hash: ItemHash) -> Tuple[List[Executor], List[Executor]]: aleph_selection_policy = ExecuteOnAleph(vm_function=executor_item_hash) executors = await aleph_selection_policy.get_candidate_executors() - prepare_tasks = [] - for executor in executors: - prepare_tasks.append( - asyncio.create_task( - prepare_executor_api_request(executor.api_url) - ) - ) + prepare_tasks = [asyncio.create_task(prepare_executor_api_request(executor.api_url)) + for executor in executors] vrf_prepare_responses = await asyncio.gather( *prepare_tasks, return_exceptions=True @@ -51,13 +46,9 @@ async def prepare_executor_nodes(executor_item_hash: ItemHash) -> Tuple[List[Exe def create_unauthorized_file(unauthorized_executors: List[Executor]): source_dir = Path(__file__).parent.parent / "src" - unauthorized_nodes = [] - for unauthorized_executor in unauthorized_executors: - unauthorized_nodes.append(unauthorized_executor.node.address) - + unauthorized_nodes = [executor.node.address for executor in unauthorized_executors] unauthorized_nodes_list_path = source_dir / "aleph_vrf" / "coordinator" / "unauthorized_node_list.json" - with open(unauthorized_nodes_list_path, mode="w") as unauthorized_file: - unauthorized_file.write(json.dumps(unauthorized_nodes)) + unauthorized_nodes_list_path.write_text(json.dumps(unauthorized_nodes)) print(f"Unauthorized node list file created on {unauthorized_nodes_list_path}") @@ -69,7 +60,7 @@ async def main(args: argparse.Namespace): print("Aleph.im VRF VMs nodes prepared.") - if len(failed_nodes) > 0: + if failed_nodes: print(f"{len(failed_nodes)} preload nodes failed.") create_unauthorized_file(failed_nodes) diff --git a/src/aleph_vrf/coordinator/vrf.py b/src/aleph_vrf/coordinator/vrf.py index f4de029..01f2b07 100644 --- a/src/aleph_vrf/coordinator/vrf.py +++ b/src/aleph_vrf/coordinator/vrf.py @@ -65,14 +65,14 @@ async def post_executor_api_request(url: str, model: Type[M]) -> M: async def prepare_executor_api_request(url: str) -> bool: async with aiohttp.ClientSession() as session: async with session.get(url, timeout=120) as resp: - if resp.status != 200: + try: + resp.raise_for_status() + response = await resp.json() + return response["name"] == "vrf_generate_api" + except aiohttp.ClientResponseError as error: raise ExecutorHttpError( url=url, status_code=resp.status, response_text=await resp.text() - ) - - response = await resp.json() - - return response["name"] == "vrf_generate_api" + ) from error async def _generate_vrf(