Spaces:
Sleeping
Sleeping
[NOTICKET] Add pool_pre_ping to validate db connection
Browse files
externals/databases/database.py
CHANGED
|
@@ -14,7 +14,9 @@ DATABASE_URL = EnvPostgresConstants.CONSTRING.\
|
|
| 14 |
engine = create_async_engine(
|
| 15 |
DATABASE_URL,
|
| 16 |
echo=False,
|
| 17 |
-
future=True
|
|
|
|
|
|
|
| 18 |
)
|
| 19 |
|
| 20 |
AsyncSessionLocal = async_sessionmaker(
|
|
@@ -48,10 +50,10 @@ async def get_db():
|
|
| 48 |
# raise
|
| 49 |
|
| 50 |
|
| 51 |
-
@asynccontextmanager
|
| 52 |
-
async def db_session():
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
| 14 |
engine = create_async_engine(
|
| 15 |
DATABASE_URL,
|
| 16 |
echo=False,
|
| 17 |
+
future=True,
|
| 18 |
+
pool_pre_ping=True,
|
| 19 |
+
pool_recycle=300,
|
| 20 |
)
|
| 21 |
|
| 22 |
AsyncSessionLocal = async_sessionmaker(
|
|
|
|
| 50 |
# raise
|
| 51 |
|
| 52 |
|
| 53 |
+
# @asynccontextmanager
|
| 54 |
+
# async def db_session():
|
| 55 |
+
# async with AsyncSessionLocal() as session:
|
| 56 |
+
# try:
|
| 57 |
+
# yield session
|
| 58 |
+
# finally:
|
| 59 |
+
# await session.close()
|