From 42a9998b14bb519a4260601131320fd37188424e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Fri, 10 Jun 2022 17:30:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BA=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Жирный грязный try excert --- solution.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/solution.py b/solution.py index 8810b32..28f3c76 100644 --- a/solution.py +++ b/solution.py @@ -100,20 +100,23 @@ async def send_async_request(cfg: Config, json_body: dict) -> None: url = cfg.central_host_url portion = cfg.request_portion - async with aiohttp.ClientSession(connector=conn) as session: - # получаем количесвто записей - count = await get_records_count(session, url) - - tasks = await get_tasks(f"{url}/get", portion, count, session, json_body) - - responses = await asyncio.gather(*tasks) - - # Пройдемся по ответам на запросы, запишем файлы конфига для - # каждого respone. Каждый response содержит portion или меньше хостов - for response in responses: - resp = await response.json() - hosts = [i["hostname"] for i in resp.get("result")] - await write_config_files(hosts, cfg, template) + try: + async with aiohttp.ClientSession(connector=conn) as session: + # получаем количесвто записей + count = await get_records_count(session, url) + + tasks = await get_tasks(f"{url}/get", portion, count, session, json_body) + + responses = await asyncio.gather(*tasks) + + # Пройдемся по ответам на запросы, запишем файлы конфига для + # каждого respone. Каждый response содержит portion или меньше хостов + for response in responses: + resp = await response.json() + hosts = [i["hostname"] for i in resp.get("result")] + await write_config_files(hosts, cfg, template) + except ClientConnectorError: + print(f"Невозможно подключиться к серверу {url}") def read_config(path_to_conf_file: str, section: str = "Main") -> Config: