v2026.06
This commit is contained in:
30
app/api.py
30
app/api.py
@@ -1,3 +1,4 @@
|
||||
from contextlib import asynccontextmanager
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
@@ -49,24 +50,37 @@ def create_app():
|
||||
if FastAPI is None:
|
||||
return None
|
||||
|
||||
api = FastAPI(title="Syncio Migration API", version="0.1.0")
|
||||
_shared: dict = {}
|
||||
|
||||
@api.on_event("startup")
|
||||
def startup_queue():
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
config = Config()
|
||||
_shared['engine'] = create_engine(
|
||||
config.POSTGRES_CONNECTION_STRING,
|
||||
pool_pre_ping=True,
|
||||
pool_recycle=1800,
|
||||
)
|
||||
_shared['config'] = config
|
||||
if Config.START_API_WORKER:
|
||||
migration_queue.start()
|
||||
|
||||
yield
|
||||
|
||||
engine = _shared.get('engine')
|
||||
if engine is not None:
|
||||
engine.dispose()
|
||||
|
||||
api = FastAPI(title="Syncio Migration API", version="0.1.0", lifespan=lifespan)
|
||||
|
||||
@api.get("/health")
|
||||
def health():
|
||||
return {"status": "ok"}
|
||||
|
||||
@api.get("/tables")
|
||||
def tables():
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
config = Config()
|
||||
engine = create_engine(config.POSTGRES_CONNECTION_STRING)
|
||||
repository = TableConfigRepository(config, engine)
|
||||
repository = TableConfigRepository(_shared['config'], _shared['engine'])
|
||||
table_configs = repository.load_configs(seed_defaults=True)
|
||||
return [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user