@@ -121,17 +121,6 @@ class ClusterMember(TypedDict):
121
121
lag : int
122
122
123
123
124
- async def _aiohttp_get_request (session , ssl_ctx , url ):
125
- try :
126
- async with session .get (url , ssl = ssl_ctx ) as response :
127
- if response .status > 299 :
128
- logger .debug ("Call failed with status code {response.status}: {response.text()}" )
129
- return
130
- return await response .json ()
131
- except (ClientError , ValueError ):
132
- return None
133
-
134
-
135
124
class Patroni :
136
125
"""This class handles the bootstrap of a PostgreSQL database through Patroni."""
137
126
@@ -311,7 +300,7 @@ def get_member_status(self, member_name: str) -> str:
311
300
return member ["state" ]
312
301
return ""
313
302
314
- async def _async_get_request (self , uri , endpoints ):
303
+ async def _aiohttp_get_request (self , url ):
315
304
ssl_ctx = ssl .create_default_context ()
316
305
try :
317
306
ssl_ctx .load_verify_locations (cafile = f"{ PATRONI_CONF_PATH } /{ TLS_CA_FILE } " )
@@ -321,16 +310,24 @@ async def _async_get_request(self, uri, endpoints):
321
310
auth = self ._patroni_async_auth ,
322
311
timeout = ClientTimeout (total = API_REQUEST_TIMEOUT ),
323
312
) as session :
324
- tasks = [
325
- _aiohttp_get_request (session , ssl_ctx , f"http://{ ip } :8008{ uri } " )
326
- for ip in endpoints
327
- ] + [
328
- _aiohttp_get_request (session , ssl_ctx , f"https://{ ip } :8008{ uri } " )
329
- for ip in endpoints
330
- ]
331
- for routine in as_completed (tasks ):
332
- if result := await routine :
333
- return result
313
+ try :
314
+ async with session .get (url , ssl = ssl_ctx ) as response :
315
+ if response .status > 299 :
316
+ logger .debug (
317
+ "Call failed with status code {response.status}: {response.text()}"
318
+ )
319
+ return
320
+ return await response .json ()
321
+ except (ClientError , ValueError ):
322
+ return None
323
+
324
+ 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 :
330
+ return result
334
331
335
332
def parallel_patroni_get_request (self , uri : str , endpoints : list [str ] | None = None ) -> dict :
336
333
"""Call all possible patroni endpoints in parallel."""
0 commit comments