File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed
scripts/maintenance/computational-clusters/autoscaled_monitor Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ def _parse_environment(deploy_config: Path) -> dict[str, str | None]:
5050def main (
5151 deploy_config : Annotated [
5252 Path , typer .Option (help = "path to the deploy configuration" )
53- ]
53+ ],
5454):
5555 """Manages external clusters"""
5656
@@ -157,5 +157,11 @@ def trigger_cluster_termination(
157157 asyncio .run (api .trigger_cluster_termination (state , user_id , wallet_id ))
158158
159159
160+ @app .command ()
161+ def test_database_connection () -> None :
162+ """this will check the connection to simcore database is ready"""
163+ asyncio .run (api .test_database_connection (state ))
164+
165+
160166if __name__ == "__main__" :
161167 app ()
Original file line number Diff line number Diff line change @@ -638,3 +638,7 @@ async def trigger_cluster_termination(
638638 )
639639 else :
640640 rich .print ("not deleting anything" )
641+
642+
643+ async def test_database_connection (state : AppState ) -> None :
644+ await db .test_db_connection (state )
Original file line number Diff line number Diff line change @@ -57,6 +57,23 @@ async def abort_job_in_db(
5757 rich .print (f"set comp_tasks for { project_id = } /{ node_id = } set to ABORTED" )
5858
5959
60+ async def test_db_connection (state : AppState ) -> bool :
61+ try :
62+ async with contextlib .AsyncExitStack () as stack :
63+ engine = await stack .enter_async_context (db_engine (state ))
64+ db_connection = await stack .enter_async_context (engine .connect ())
65+ # Perform a simple query to test the connection
66+ result = await db_connection .execute (sa .text ("SELECT 1" ))
67+ result .one ()
68+ rich .print (
69+ "[green]Database connection test completed successfully![/green]"
70+ )
71+ return True
72+ except Exception as e : # pylint: disable=broad-exception-caught
73+ rich .print (f"[red]Database connection test failed: { e } [/red]" )
74+ return False
75+
76+
6077async def list_computational_tasks_from_db (
6178 state : AppState , user_id : int
6279) -> list [ComputationalTask ]:
You can’t perform that action at this time.
0 commit comments