@@ -302,23 +302,7 @@ def read_locals(self) -> dict:
302302 return node
303303 raise FatalException (f"No { config_file } found. Exiting." )
304304
305- async def init_db (self ):
306- async def check_db (url : str ) -> str | None :
307- max_attempts = self .locals .get ("database" , self .config .get ('database' )).get ('max_retries' , 10 )
308- for attempt in range (max_attempts + 1 ):
309- try :
310- aconn = await psycopg .AsyncConnection .connect (url , connect_timeout = 5 )
311- async with aconn :
312- cursor = await aconn .execute ("SHOW server_version" )
313- return (await cursor .fetchone ())[0 ]
314- except ConnectionTimeout :
315- if attempt < max_attempts :
316- self .log .warning ("- Database not available (yet), trying again ..." )
317- continue
318- raise
319- # we will never be here
320- return None
321-
305+ def get_database_urls (self ):
322306 cpool_url = self .config .get ("database" , self .locals .get ('database' ))['url' ]
323307 lpool_url = self .locals .get ("database" , self .config .get ('database' ))['url' ]
324308
@@ -343,7 +327,26 @@ async def check_db(url: str) -> str | None:
343327
344328 cpool_url = cpool_url .replace ('SECRET' , quote (cpool_pwd ) or '' )
345329 lpool_url = lpool_url .replace ('SECRET' , quote (lpool_pwd ) or '' )
330+ return cpool_url , lpool_url
331+
332+ async def init_db (self ):
333+ async def check_db (url : str ) -> str | None :
334+ max_attempts = self .locals .get ("database" , self .config .get ('database' )).get ('max_retries' , 10 )
335+ for attempt in range (max_attempts + 1 ):
336+ try :
337+ aconn = await psycopg .AsyncConnection .connect (url , connect_timeout = 5 )
338+ async with aconn :
339+ cursor = await aconn .execute ("SHOW server_version" )
340+ return (await cursor .fetchone ())[0 ]
341+ except ConnectionTimeout :
342+ if attempt < max_attempts :
343+ self .log .warning ("- Database not available (yet), trying again ..." )
344+ continue
345+ raise
346+ # we will never be here
347+ return None
346348
349+ cpool_url , lpool_url = self .get_database_urls ()
347350 version = await check_db (lpool_url )
348351 if lpool_url != cpool_url :
349352 await check_db (cpool_url )
0 commit comments