1111 BROOD_DB_URI_READ_ONLY ,
1212 BROOD_POOL_SIZE ,
1313 BROOD_DB_STATEMENT_TIMEOUT_MILLIS ,
14+ BROOD_DB_POOL_RECYCLE_SECONDS ,
1415)
1516
1617
17- def create_brood_engine (url : Optional [str ], pool_size : int , statement_timeout : int ):
18+ def create_brood_engine (
19+ url : Optional [str ],
20+ pool_size : int ,
21+ statement_timeout : int ,
22+ pool_recycle : int = BROOD_DB_POOL_RECYCLE_SECONDS ,
23+ ):
1824 # Pooling: https://docs.sqlalchemy.org/en/14/core/pooling.html#sqlalchemy.pool.QueuePool
1925 # Statement timeout: https://stackoverflow.com/a/44936982
2026 return create_engine (
2127 url = url ,
2228 pool_size = pool_size ,
29+ pool_recycle = pool_recycle ,
2330 connect_args = {"options" : f"-c statement_timeout={ statement_timeout } " },
2431 )
2532
@@ -28,6 +35,7 @@ def create_brood_engine(url: Optional[str], pool_size: int, statement_timeout: i
2835 url = BROOD_DB_URI ,
2936 pool_size = BROOD_POOL_SIZE ,
3037 statement_timeout = BROOD_DB_STATEMENT_TIMEOUT_MILLIS ,
38+ pool_recycle = BROOD_DB_POOL_RECYCLE_SECONDS ,
3139)
3240SessionLocal = sessionmaker (autocommit = False , autoflush = False , bind = engine )
3341
@@ -52,6 +60,7 @@ def yield_db_session_from_env() -> Session:
5260 url = BROOD_DB_URI_READ_ONLY ,
5361 pool_size = BROOD_POOL_SIZE ,
5462 statement_timeout = BROOD_DB_STATEMENT_TIMEOUT_MILLIS ,
63+ pool_recycle = BROOD_DB_POOL_RECYCLE_SECONDS ,
5564)
5665RO_SessionLocal = sessionmaker (autocommit = False , autoflush = False , bind = RO_engine )
5766
0 commit comments