import asyncio
import sys
from sqlalchemy import text
from app.core.db import SessionLocal


async def main() -> int:
    retries = 30
    for _ in range(retries):
        try:
            async with SessionLocal() as session:
                await session.execute(text("SELECT 1"))
            return 0
        except Exception:
            await asyncio.sleep(2)
    return 1


if __name__ == "__main__":
    raise SystemExit(asyncio.run(main()))
