Recover stale PostgreSQL connections before starting requests
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user