fix: add pool_pre_ping and pool_recycle to prevent connection errors

This commit is contained in:
Ricel Leite 2026-02-19 00:22:37 -03:00
parent bd8ba302a8
commit 4c294965f2
1 changed files with 8 additions and 1 deletions

View File

@ -6,7 +6,14 @@ from .config import settings
# Convert sync URL to async
DATABASE_URL = settings.DATABASE_URL.replace("postgresql://", "postgresql+asyncpg://")
engine = create_async_engine(DATABASE_URL, echo=settings.DEBUG, pool_size=10, max_overflow=20)
engine = create_async_engine(
DATABASE_URL,
echo=settings.DEBUG,
pool_size=10,
max_overflow=20,
pool_pre_ping=True, # Test connection before using
pool_recycle=3600 # Recycle connections after 1 hour
)
async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
Base = declarative_base()