Балансировка, реплики, идемпотентность

This commit is contained in:
Queenfish
2026-10-16 01:07:34 +03:00
parent 0ab3a341aa
commit cb11011869
59 changed files with 3916 additions and 27 deletions
+30
View File
@@ -0,0 +1,30 @@
import asyncpg
from app.config import config
class Database:
def __init__(self) -> None:
self._pool: asyncpg.Pool | None = None
async def connect(self) -> None:
self._pool = await asyncpg.create_pool(
config.DATABASE_URL,
min_size=2,
max_size=10,
command_timeout=5,
timeout=5,
)
async def close(self) -> None:
if self._pool is not None:
await self._pool.close()
self._pool = None
@property
def pool(self) -> asyncpg.Pool:
if self._pool is None:
raise RuntimeError("database is not connected")
return self._pool
db = Database()