Skip to content

Commit

Permalink
Fix: Applied PR review fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres D. Molins committed Jan 23, 2024
1 parent 72b9f50 commit fc3aa83
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
19 changes: 5 additions & 14 deletions deployment/prepare_vrf_vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}")

Expand All @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions src/aleph_vrf/coordinator/vrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit fc3aa83

Please sign in to comment.