Files
ai-shiliu/app/infrastructure/backend.py

26 lines
847 B
Python
Raw Normal View History

from app.infrastructure.service.backend.config import app
from app.infrastructure.service.backend.db import init_db
from app.infrastructure.router.backend_routes import register_routes
from app.infrastructure.service.logging.log_service import init_logging, log_event, new_trace_id
init_logging()
register_routes(app)
def init_backend():
trace_id = new_trace_id("backend")
try:
init_db()
log_event("INFO", "db", "db.init", trace_id, "boot", "ok", "数据库初始化成功")
except Exception as err:
log_event("ERROR", "db", "db.error", trace_id, "boot", "fail", "数据库初始化失败", reason=type(err).__name__)
raise
return app
def start_backend(host="127.0.0.1", port=5000, threaded=True):
backend_app = init_backend()
backend_app.run(host=host, port=port, threaded=threaded)