Skip to content

fix: update tipg startup for 1.0 #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 17 additions & 30 deletions lib/tipg-api/runtime/src/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,24 @@
import os

from mangum import Mangum
from tipg.collections import register_collection_catalog
from tipg.database import connect_to_db
from tipg.main import app
from tipg.settings import (
CustomSQLSettings,
DatabaseSettings,
PostgresSettings,
)
from utils import get_secret_dict

secret = get_secret_dict(secret_arn_env_var="PGSTAC_SECRET_ARN")
os.environ.update(
{
"postgres_host": secret["host"],
"postgres_dbname": secret["dbname"],
"postgres_user": secret["username"],
"postgres_pass": secret["password"],
"postgres_port": str(secret["port"]),
}
)

from tipg.collections import register_collection_catalog # noqa: E402
from tipg.database import connect_to_db # noqa: E402

# skipping linting rule that wants all imports at the top
from tipg.main import app # noqa: E402
from tipg.settings import (
CustomSQLSettings, # noqa: E402
DatabaseSettings, # noqa: E402
PostgresSettings, # noqa: E402; noqa: E402
postgres_settings = PostgresSettings(
postgres_host=secret["host"],
postgres_dbname=secret["dbname"],
postgres_user=secret["username"],
postgres_pass=secret["password"],
postgres_port=int(secret["port"]),
)

postgres_settings = PostgresSettings()
db_settings = DatabaseSettings()
custom_sql_settings = CustomSQLSettings()

Expand All @@ -40,20 +33,14 @@ async def startup_event() -> None:
"""Connect to database on startup."""
await connect_to_db(
app,
settings=postgres_settings,
schemas=db_settings.schemas,
tipg_schema=db_settings.tipg_schema,
user_sql_files=custom_sql_settings.sql_files,
settings=postgres_settings,
)
await register_collection_catalog(
app,
schemas=db_settings.schemas,
tables=db_settings.tables,
exclude_tables=db_settings.exclude_tables,
exclude_table_schemas=db_settings.exclude_table_schemas,
functions=db_settings.functions,
exclude_functions=db_settings.exclude_functions,
exclude_function_schemas=db_settings.exclude_function_schemas,
spatial=db_settings.only_spatial_tables,
db_settings=db_settings,
)


Expand Down
22 changes: 10 additions & 12 deletions lib/titiler-pgstac-api/runtime/src/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,25 @@
import os

from mangum import Mangum
from titiler.pgstac.db import connect_to_db
from titiler.pgstac.main import app
from titiler.pgstac.settings import PostgresSettings
from utils import get_secret_dict

secret = get_secret_dict(secret_arn_env_var="PGSTAC_SECRET_ARN")
os.environ.update(
{
"postgres_host": secret["host"],
"postgres_dbname": secret["dbname"],
"postgres_user": secret["username"],
"postgres_pass": secret["password"],
"postgres_port": str(secret["port"]),
}
postgres_settings = PostgresSettings(
postgres_host=secret["host"],
postgres_dbname=secret["dbname"],
postgres_user=secret["username"],
postgres_pass=secret["password"],
postgres_port=int(secret["port"]),
)

from titiler.pgstac.db import connect_to_db # noqa: E402
from titiler.pgstac.main import app # noqa: E402


@app.on_event("startup")
async def startup_event() -> None:
"""Connect to database on startup."""
await connect_to_db(app)
await connect_to_db(app, settings=postgres_settings)


handler = Mangum(app, lifespan="off")
Expand Down
Loading