From 2017dba2851153c54eafea08712b0c1ebd895346 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Mon, 25 Sep 2023 22:26:25 +0200 Subject: [PATCH] add try/expect to avoid failure in startup --- cerulean_cloud/cloud_run_tipg/handler.py | 33 ++++++++++++++---------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/cerulean_cloud/cloud_run_tipg/handler.py b/cerulean_cloud/cloud_run_tipg/handler.py index 7d41fa90..9c16a740 100644 --- a/cerulean_cloud/cloud_run_tipg/handler.py +++ b/cerulean_cloud/cloud_run_tipg/handler.py @@ -10,6 +10,7 @@ """ import logging +import warnings from typing import Any, List, Optional import jinja2 @@ -109,20 +110,24 @@ class Config: @app.on_event("startup") async def startup_event() -> None: """Connect to database on startup.""" - await connect_to_db(app, settings=postgres_settings) - assert getattr(app.state, "pool", None) - - await register_collection_catalog( - app, - schemas=db_settings.schemas, - exclude_table_schemas=db_settings.exclude_table_schemas, - tables=db_settings.tables, - exclude_tables=db_settings.exclude_tables, - exclude_function_schemas=db_settings.exclude_function_schemas, - functions=db_settings.functions, - exclude_functions=db_settings.exclude_functions, - spatial=False, # False means allow non-spatial tables - ) + try: + await connect_to_db(app, settings=postgres_settings) + assert getattr(app.state, "pool", None) + + await register_collection_catalog( + app, + schemas=db_settings.schemas, + exclude_table_schemas=db_settings.exclude_table_schemas, + tables=db_settings.tables, + exclude_tables=db_settings.exclude_tables, + exclude_function_schemas=db_settings.exclude_function_schemas, + functions=db_settings.functions, + exclude_functions=db_settings.exclude_functions, + spatial=False, # False means allow non-spatial tables + ) + except: # noqa + warnings.warn("Could not initiate TiPg", UserWarning) + pass @app.on_event("shutdown")