x
This commit is contained in:
@@ -10,28 +10,22 @@ sys.path.insert(0, str(src_root))
|
||||
os.chdir(Path(__file__).parent.parent.parent)
|
||||
|
||||
from shared.app_factory import create_app
|
||||
from moldinsight.storage.init_storage import rustfs_startup_hook
|
||||
|
||||
|
||||
def _register_routers(app):
|
||||
"""注册 moldinsight 业务路由"""
|
||||
"""注册 moldinsight 业务路由(/api 聚合 + HTML 报告代理,收敛于 moldinsight.api)"""
|
||||
try:
|
||||
from moldinsight.api import router as moldinsight_router
|
||||
app.include_router(moldinsight_router, prefix="/api")
|
||||
from moldinsight.api import register_moldinsight_routers
|
||||
register_moldinsight_routers(app)
|
||||
except Exception as e:
|
||||
print(f"[WARN] MoldInsight 路由: {e}")
|
||||
|
||||
# D11:HTML 报告代理挂根路径,URL 形状与原 StaticFiles 保持一致(/html/{filename})
|
||||
try:
|
||||
from moldinsight.api.html_report_router import include_into as include_html_report
|
||||
include_html_report(app)
|
||||
except Exception as e:
|
||||
print(f"[WARN] HTML 报告路由: {e}")
|
||||
|
||||
|
||||
app = create_app(
|
||||
title="Gemold - 模具分析引擎",
|
||||
service_name="moldinsight",
|
||||
connect_rustfs=True,
|
||||
serve_frontend_static=False,
|
||||
startup_hooks=[rustfs_startup_hook],
|
||||
register_routers=_register_routers,
|
||||
)
|
||||
|
||||
@@ -10,23 +10,17 @@ sys.path.insert(0, str(src_root))
|
||||
os.chdir(Path(__file__).parent.parent.parent)
|
||||
|
||||
from shared.app_factory import create_app
|
||||
from moldinsight.storage.init_storage import rustfs_startup_hook
|
||||
|
||||
|
||||
def _register_routers(app):
|
||||
"""注册 unified 业务路由"""
|
||||
"""注册 unified 业务路由(moldinsight 单点聚合 + inventory)"""
|
||||
try:
|
||||
from moldinsight.api import router as moldinsight_router
|
||||
app.include_router(moldinsight_router, prefix="/api")
|
||||
from moldinsight.api import register_moldinsight_routers
|
||||
register_moldinsight_routers(app)
|
||||
except Exception as e:
|
||||
print(f"[WARN] MoldInsight 路由: {e}")
|
||||
|
||||
# D11:HTML 报告代理挂根路径,URL 形状与原 StaticFiles 保持一致(/html/{filename})
|
||||
try:
|
||||
from moldinsight.api.html_report_router import include_into as include_html_report
|
||||
include_html_report(app)
|
||||
except Exception as e:
|
||||
print(f"[WARN] HTML 报告路由: {e}")
|
||||
|
||||
try:
|
||||
from inventory.api import inventory_router
|
||||
app.include_router(inventory_router)
|
||||
@@ -37,7 +31,7 @@ def _register_routers(app):
|
||||
app = create_app(
|
||||
title="Gemold - Unified Backend",
|
||||
service_name="unified",
|
||||
connect_rustfs=True,
|
||||
serve_frontend_static=False,
|
||||
startup_hooks=[rustfs_startup_hook],
|
||||
register_routers=_register_routers,
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@ import importlib
|
||||
from shared.config.settings import settings
|
||||
from shared.utils.logger import get_logger
|
||||
from moldinsight.api.route_registry import route_load_status
|
||||
from moldinsight.api.html_report_router import include_into as include_html_report
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -54,3 +55,15 @@ def _safe_include(label: str, module_path: str, debug_only: bool = False):
|
||||
|
||||
for _label, _module_path, _debug_only in ROUTE_MODULES:
|
||||
_safe_include(_label, _module_path, _debug_only)
|
||||
|
||||
|
||||
def register_moldinsight_routers(app):
|
||||
"""注册 moldinsight 全部业务路由到 app(D3 收敛:入口侧单点调用)。
|
||||
|
||||
- /api 聚合路由:各子路由模块装载失败经 ROUTE_MODULES/route_load_status 呈现
|
||||
(/api/health degraded,DEBUG fail-fast),见 _safe_include
|
||||
- HTML 报告代理挂根路径 /html/{filename}(URL 形状与原 StaticFiles 一致),
|
||||
失败同样登记 route_load_status(html_report_router.include_into)
|
||||
"""
|
||||
app.include_router(router, prefix="/api")
|
||||
include_html_report(app)
|
||||
|
||||
@@ -36,6 +36,15 @@ async def init_rustfs_storage():
|
||||
return False
|
||||
|
||||
|
||||
async def rustfs_startup_hook():
|
||||
"""app_factory startup_hooks 注入点(D3 收敛):moldinsight/unified 入口把
|
||||
本钩子传入 create_app(startup_hooks=[rustfs_startup_hook]),RustFS 连接接线
|
||||
归属 moldinsight 层,平台工厂不再持有模块专属依赖(原 connect_rustfs 已移除)。
|
||||
"""
|
||||
ok = await init_rustfs_storage()
|
||||
print(f"[{'OK' if ok else 'WARN'}] RustFS")
|
||||
|
||||
|
||||
async def test_storage():
|
||||
"""测试 RustFS 对象存储功能"""
|
||||
try:
|
||||
|
||||
@@ -27,7 +27,6 @@ def create_app(
|
||||
title: str,
|
||||
service_name: str,
|
||||
version: str = "4.0.0",
|
||||
connect_rustfs: bool = False,
|
||||
serve_frontend_static: bool = False,
|
||||
startup_hooks: Optional[List[Callable[[], Awaitable[None]]]] = None,
|
||||
register_routers: Optional[Callable[[FastAPI], None]] = None,
|
||||
@@ -38,11 +37,10 @@ def create_app(
|
||||
title: 应用标题
|
||||
service_name: 服务名(用于 /health 响应)
|
||||
version: 版本号
|
||||
connect_rustfs: 是否连接 RustFS 对象存储(moldinsight 需要)。
|
||||
D11:/html 报告读取由 moldinsight.api.html_report_router 代理
|
||||
(RustFS 报告键直取 + 遗留对象/本地卷兜底),不再挂本地 StaticFiles。
|
||||
serve_frontend_static: 是否由后端托管 /static 与 SPA fallback(默认关闭,前端独立部署)
|
||||
startup_hooks: 额外的 startup 钩子列表(在数据库/RustFS/Redis 初始化后执行)
|
||||
startup_hooks: 额外的 startup 钩子列表(在数据库/Redis 初始化后执行)。
|
||||
模块专属的启动接线(如 moldinsight 的 RustFS 连接)经此参数注入——
|
||||
D3 收敛:平台工厂不再持有模块专属依赖(原 connect_rustfs 已移除)。
|
||||
register_routers: 回调函数,用于注册业务路由
|
||||
"""
|
||||
app = FastAPI(title=title, version=version)
|
||||
@@ -115,20 +113,6 @@ def create_app(
|
||||
success = await init_database(keep_connected=True)
|
||||
print(f"[{'OK' if success else 'FAIL'}] 数据库初始化")
|
||||
|
||||
# RustFS(仅 moldinsight 需要)
|
||||
if connect_rustfs:
|
||||
try:
|
||||
from moldinsight.storage.rustfs_storage import rustfs_manager
|
||||
await rustfs_manager.connect(
|
||||
endpoint=settings.RUSTFS_ENDPOINT,
|
||||
access_key=settings.RUSTFS_ACCESS_KEY,
|
||||
secret_key=settings.RUSTFS_SECRET_KEY,
|
||||
timeout=settings.RUSTFS_TIMEOUT,
|
||||
)
|
||||
print("[OK] RustFS连接成功")
|
||||
except Exception as e:
|
||||
print(f"[WARN] RustFS连接失败: {e}")
|
||||
|
||||
# Redis
|
||||
try:
|
||||
from shared.services.redis_task_manager import redis_task_manager
|
||||
|
||||
Reference in New Issue
Block a user