微信小程序页面迁移校验之前 P5任务处理之前

This commit is contained in:
Neo
2026-03-09 01:19:21 +08:00
parent 263bf96035
commit 6e20987d2f
1112 changed files with 153824 additions and 219694 deletions

View File

@@ -12,10 +12,12 @@ from fastapi.middleware.cors import CORSMiddleware
from app import config
# CHANGE 2026-02-19 | 新增 xcx_test 路由MVP 验证)+ wx_callback 路由(微信消息推送)
# CHANGE 2026-02-22 | 新增 member_birthday 路由(助教手动补录会员生日)
# CHANGE 2026-02-23 | 新增 ops_panel 路由(运维控制面板)
# CHANGE 2026-02-25 | 新增 xcx_auth 路由(小程序微信登录 + 申请 + 状态查询 + 店铺切换)
from app.routers import auth, execution, schedules, tasks, env_config, db_viewer, etl_status, xcx_test, wx_callback, member_birthday, ops_panel, xcx_auth
# CHANGE 2026-02-26 | member_birthday 路由替换为 member_retention_clue维客线索重构
# CHANGE 2026-02-26 | 新增 admin_applications 路由(管理端申请审核)
# CHANGE 2026-02-27 | 新增 xcx_tasks / xcx_notes 路由(小程序核心业务)
from app.routers import auth, execution, schedules, tasks, env_config, db_viewer, etl_status, xcx_test, wx_callback, member_retention_clue, ops_panel, xcx_auth, admin_applications, business_day, xcx_tasks, xcx_notes
from app.services.scheduler import scheduler
from app.services.task_queue import task_queue
from app.ws.logs import ws_router
@@ -24,9 +26,37 @@ from app.ws.logs import ws_router
@asynccontextmanager
async def lifespan(app: FastAPI):
"""应用生命周期:启动时拉起后台服务,关闭时优雅停止。"""
# CHANGE 2026-03-07 | 启动横幅:打印关键路径,便于诊断连到了哪个实例
import sys
_banner = (
"\n"
"╔══════════════════════════════════════════════════════╗\n"
"║ NeoZQYY Backend — 启动诊断 ║\n"
"╠══════════════════════════════════════════════════════╣\n"
f"║ Python: {sys.executable}\n"
f"║ ROOT: {config._project_root}\n"
f"║ ETL_PATH: {config.ETL_PROJECT_PATH}\n"
f"║ ETL_PY: {config.ETL_PYTHON_EXECUTABLE}\n"
f"║ OPS_BASE: {config.OPS_SERVER_BASE}\n"
f"║ APP_DB: {config.APP_DB_NAME}\n"
f"║ .env: {config._root_env}\n"
"╚══════════════════════════════════════════════════════╝\n"
)
print(_banner, flush=True)
# 启动
task_queue.start()
scheduler.start()
# CHANGE 2026-02-27 | 注册触发器 job handler核心业务模块
from app.services.trigger_scheduler import register_job
from app.services import task_generator, task_expiry, recall_detector, note_reclassifier
register_job("task_generator", lambda **_kw: task_generator.run())
register_job("task_expiry_check", lambda **_kw: task_expiry.run())
register_job("recall_completion_check", recall_detector.run)
register_job("note_reclassify_backfill", note_reclassifier.run)
yield
# 关闭
await scheduler.stop()
@@ -63,12 +93,47 @@ app.include_router(etl_status.router)
app.include_router(ws_router)
app.include_router(xcx_test.router)
app.include_router(wx_callback.router)
app.include_router(member_birthday.router)
app.include_router(member_retention_clue.router)
app.include_router(ops_panel.router)
app.include_router(xcx_auth.router)
app.include_router(admin_applications.router)
app.include_router(business_day.router)
app.include_router(xcx_tasks.router)
app.include_router(xcx_notes.router)
@app.get("/health", tags=["系统"])
async def health_check():
"""健康检查端点,用于探活和监控。"""
return {"status": "ok"}
# CHANGE 2026-03-07 | 诊断端点:返回关键路径配置,用于确认连到的是哪个实例
@app.get("/debug/config-paths", tags=["系统"])
async def debug_config_paths():
"""返回当前后端实例的关键路径配置(仅开发环境使用)。"""
import sys
import os
import platform
from app.services.cli_builder import cli_builder as _cb
from app.schemas.tasks import TaskConfigSchema as _TCS
_test_cfg = _TCS(flow="api_ods_dwd", processing_mode="increment_only",
tasks=["DWD_LOAD_FROM_ODS"], store_id=123)
_test_cmd = _cb.build_command(
_test_cfg, config.ETL_PROJECT_PATH,
python_executable=config.ETL_PYTHON_EXECUTABLE,
)
_test_cmd_str = " ".join(_test_cmd)
return {
"hostname": platform.node(),
"python_executable": sys.executable,
"project_root": str(config._project_root),
"env_file": str(config._root_env),
"etl_python_executable": config.ETL_PYTHON_EXECUTABLE,
"etl_project_path": config.ETL_PROJECT_PATH,
"simulated_command": _test_cmd_str,
"NEOZQYY_ROOT_env": os.environ.get("NEOZQYY_ROOT", "<未设置>"),
"cwd": os.getcwd(),
}