From e797c48059ed7a6d4b181ad3d84ada2725d7d3d9 Mon Sep 17 00:00:00 2001 From: sudobangbang Date: Fri, 9 Jun 2023 11:06:57 -0700 Subject: [PATCH] apply ttl (#24) Co-authored-by: ranchodeluxe --- terraform/veda-wfs3/ecs_api.tf | 4 ++++ veda-wfs3-app/fast_api_main.py | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/terraform/veda-wfs3/ecs_api.tf b/terraform/veda-wfs3/ecs_api.tf index a791f6e..1edbdfe 100644 --- a/terraform/veda-wfs3/ecs_api.tf +++ b/terraform/veda-wfs3/ecs_api.tf @@ -68,6 +68,10 @@ module "ecs_cluster" { // stupid hack b/c of FastAPI and Starlette bug name = "FAST_API_SCHEME" value = var.env == "west2-staging" ? "https" : "http" + }, + { + name = "TIPG_CATALOG_TTL" + value = "300" } ] diff --git a/veda-wfs3-app/fast_api_main.py b/veda-wfs3-app/fast_api_main.py index 4fb55b3..3adada4 100644 --- a/veda-wfs3-app/fast_api_main.py +++ b/veda-wfs3-app/fast_api_main.py @@ -13,7 +13,8 @@ from starlette.middleware.cors import CORSMiddleware from tipg.db import close_db_connection, connect_to_db, register_collection_catalog from tipg.factory import Endpoints as FeaturesEndpoints -from tipg.settings import PostgresSettings +from tipg.settings import PostgresSettings, APISettings, DatabaseSettings +from tipg.middleware import CatalogUpdateMiddleware from typing import Callable logger = logging.getLogger(__name__) @@ -91,6 +92,8 @@ async def dispatch(self, request, call_next): "postgres_port": db_config["port"], "postgres_dbname": db_config["dbname"] }) +api_settings = APISettings() +db_settings = DatabaseSettings() endpoints = FeaturesEndpoints(router=APIRouter(route_class=LoggerRouteHandler)) app.include_router(endpoints.router, tags=["OGC Features"]) @@ -103,6 +106,19 @@ async def dispatch(self, request, call_next): allow_methods=["GET", "POST", "OPTIONS"], allow_headers=["*"], ) +if api_settings.catalog_ttl: + app.add_middleware( + CatalogUpdateMiddleware, + ttl=api_settings.catalog_ttl, + 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, + ) @app.on_event("startup")