Recover stale PostgreSQL connections before starting requests

This commit is contained in:
Artyom
2026-11-05 21:55:14 +03:00
parent 18de595740
commit 0a1f48bd73
13 changed files with 232 additions and 8 deletions
+3 -3
View File
@@ -16,7 +16,6 @@ from alembic.config import Config
from fastapi import FastAPI
from httpx import ASGITransport, AsyncClient
from sqlalchemy import make_url
from sqlalchemy.exc import DBAPIError
from sqlalchemy.ext.asyncio import AsyncConnection, create_async_engine
from sqlalchemy.pool import NullPool
@@ -25,6 +24,7 @@ from messenger.main import create_app
from messenger.messaging.config import MessagingSettings
from messenger.shared.config import PlatformSettings
from messenger.shared.entrypoints.config import TransportSettings
from messenger.shared.infrastructure.postgres import unavailable
ROOT = Path(__file__).resolve().parents[1]
POSTGRES_IMAGE = re.compile(r"image: (postgres:\S+)")
@@ -57,8 +57,8 @@ async def migrated(dsn: str) -> None:
try:
await upgrade(dsn)
return
except OSError, DBAPIError:
if time.monotonic() > deadline:
except Exception as error:
if not unavailable(error) or time.monotonic() > deadline:
raise
await asyncio.sleep(0.5)