Skip to content

Commit 0e02299

Browse files
authored
Merge pull request #42 from pythonitalia/copilot/improve-database-connection
Add connection health checks and recycling to psycopg pool
2 parents a1ee1f3 + 5cae909 commit 0e02299

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/python_italy_bot/db/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ async def create_repository(database_url: str | None) -> AsyncRepository:
2626
if database_url and database_url.startswith("postgresql"):
2727
from psycopg_pool import AsyncConnectionPool
2828

29-
pool = AsyncConnectionPool(database_url, open=False)
29+
pool = AsyncConnectionPool(
30+
database_url,
31+
open=False,
32+
check=AsyncConnectionPool.check_connection,
33+
max_lifetime=300,
34+
)
3035
await pool.open()
3136
return PostgresRepository(pool)
3237
return InMemoryRepository()

0 commit comments

Comments
 (0)