Лабораторная 3 - Костылев - БПИ2303 - на 5 #151

Closed
akostylev2303 wants to merge 99 commits from akostylev2303/mtusi2026lab3:solution/bpi2303-kostylev into main
Showing only changes of commit 6e4c387e50 - Show all commits
@@ -16,6 +16,8 @@ FAILURES = (
asyncpg.exceptions.LockNotAvailableError,
)
PING_TIMEOUT_SECONDS = 0.4
type Connection = asyncpg.Connection
@@ -57,16 +59,16 @@ class Database:
await self._pool.close()
@asynccontextmanager
async def connection(self) -> AsyncIterator[Connection]:
async def connection(self, wait: float | None = None) -> AsyncIterator[Connection]:
try:
async with self._pool.acquire(timeout=self._acquire_timeout) as connection:
async with self._pool.acquire(timeout=wait or self._acquire_timeout) as connection:
yield connection
except FAILURES as error:
raise Unavailable("PostgreSQL недоступен") from error
async def ping(self) -> None:
async with self.connection() as connection:
await connection.fetchval("SELECT 1", timeout=1)
async with self.connection(PING_TIMEOUT_SECONDS) as connection:
await connection.fetchval("SELECT 1", timeout=PING_TIMEOUT_SECONDS)
class PostgresUnitOfWork: