Skip to content

Commit

Permalink
add try/expect to avoid failure in startup
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Sep 25, 2023
1 parent 5428dcd commit 2017dba
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions cerulean_cloud/cloud_run_tipg/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""
import logging
import warnings
from typing import Any, List, Optional

import jinja2
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 2017dba

Please sign in to comment.