Skip to content

Commit fd48c87

Browse files
committed
Back to tasks
1 parent f776858 commit fd48c87

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/cluster.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import shutil
1313
import ssl
1414
import subprocess
15-
from asyncio import as_completed, run
15+
from asyncio import as_completed, create_task, run, wait
1616
from pathlib import Path
1717
from typing import TYPE_CHECKING, Any, Optional, TypedDict
1818

@@ -322,11 +322,14 @@ async def _aiohttp_get_request(self, url):
322322
return None
323323

324324
async def _async_get_request(self, uri, endpoints):
325-
tasks = [self._aiohttp_get_request(f"http://{ip}:8008{uri}") for ip in endpoints] + [
326-
self._aiohttp_get_request(f"https://{ip}:8008{uri}") for ip in endpoints
327-
]
328-
for routine in as_completed(tasks):
329-
if result := await routine:
325+
tasks = [
326+
create_task(self._aiohttp_get_request(f"http://{ip}:8008{uri}")) for ip in endpoints
327+
] + [create_task(self._aiohttp_get_request(f"https://{ip}:8008{uri}")) for ip in endpoints]
328+
for task in as_completed(tasks):
329+
if result := task.result():
330+
for task in tasks:
331+
task.cancel()
332+
await wait(tasks)
330333
return result
331334

332335
def parallel_patroni_get_request(self, uri: str, endpoints: list[str] | None = None) -> dict:

0 commit comments

Comments
 (0)