diff --git a/backend/src/db/main.py b/backend/src/db/main.py index 4f0719af..dcbf0c32 100644 --- a/backend/src/db/main.py +++ b/backend/src/db/main.py @@ -3,7 +3,12 @@ from src.constants import CONN_STR -engine = create_engine(CONN_STR) +# pool_pre_ping: a pooled connection idle across the hourly-cron gap goes stale +# (Cloud SQL / db-f1-micro / the Cloud SQL proxy reap idle connections), and the +# next query raises "server closed the connection unexpectedly", 500ing the ETL +# trigger and stalling ingestion. pre_ping reconnects transparently; recycle +# drops connections older than 30 min proactively. +engine = create_engine(CONN_STR, pool_pre_ping=True, pool_recycle=1800) Session = sessionmaker(bind=engine)