Files
willhaben-tracker/worker/src/db.py
T
Lago afb360c3ad
CI / lint-and-test (push) Has been cancelled
Use direct PostgreSQL host
2026-07-12 21:25:39 +02:00

33 lines
820 B
Python

import os
import logging
import asyncpg
logger = logging.getLogger(__name__)
_pool: asyncpg.Pool | None = None
async def get_pool() -> asyncpg.Pool:
global _pool
if _pool is None:
_pool = await asyncpg.create_pool(
host=os.getenv("POSTGRES_HOST", "192.168.178.3"),
port=int(os.getenv("POSTGRES_PORT", "5432")),
user=os.getenv("POSTGRES_USER", "postgres"),
password=os.getenv("POSTGRES_PASSWORD"),
database=os.getenv("POSTGRES_DB", "postgres"),
min_size=2,
max_size=10,
)
logger.info("Database pool initialized")
return _pool
async def close_pool() -> None:
global _pool
if _pool is not None:
await _pool.close()
logger.info("Database pool closed")
_pool = None