fix(report): FE 问卷键名双侧兼容 + worker 持久事件循环(live E2E 两处修复)
CI / lint / typecheck / import-linter / tests / secrets (push) Canceled after 0s
CI / lint / typecheck / import-linter / tests / secrets (push) Canceled after 0s
FE↔后端联调实测暴露并修复: 1. 问卷键名三处错位(FE height_cm/weight_kg/psych_style vs 文档 height/weight/psyche_style)——vision._bmi 多键取值、diagnosis 维度 装配与规则上下文双键或运算,两侧谁改键名都不再炸 2. celery worker asyncio.run 每投递起新 loop + 模块级引擎缓存 → asyncpg 连接跨 loop(同进程第 3 个报告任务必现 RuntimeError: attached to a different loop;集成测试单循环掩盖)。新增 apps/worker/loop.py 持久 loop,report/ping 两任务接入 E2E 终态: psyche_style/height_weight 恢复、BMI 体型确定值、ok 26/32、 真实 LLM 文案通过校验 degraded=False。
This commit is contained in:
@@ -14,15 +14,15 @@ worker 侧 LLM 网关装配:apps.api.deps 属 HTTP 层,worker 不得 import
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import UTC, datetime
|
||||
from decimal import Decimal
|
||||
from typing import Any
|
||||
from typing import Any, cast
|
||||
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm.attributes import flag_modified
|
||||
|
||||
from apps.worker import loop as worker_loop
|
||||
from apps.worker.celery_app import celery_app
|
||||
from packages.billing.service import BillingService
|
||||
from packages.domain.task.state import TERMINAL_STATUSES, TaskStatus
|
||||
@@ -279,7 +279,7 @@ def generate_report(self: Any, task_id: int) -> dict[str, Any]:
|
||||
"""
|
||||
bind_context(task_id=task_id)
|
||||
try:
|
||||
return asyncio.run(_generate_report(task_id))
|
||||
return cast("dict[str, Any]", worker_loop.run(_generate_report(task_id)))
|
||||
except StageFailureError as exc:
|
||||
logger.warning(
|
||||
"report_stage_failed",
|
||||
@@ -293,5 +293,5 @@ def generate_report(self: Any, task_id: int) -> dict[str, Any]:
|
||||
logger.warning("report_generate_retry", task_id=task_id, error=str(exc))
|
||||
raise self.retry(exc=exc, countdown=10) from exc
|
||||
logger.exception("report_generate_failed_after_retry", task_id=task_id)
|
||||
asyncio.run(_fail_report(task_id, f"{type(exc).__name__}: {exc}"))
|
||||
worker_loop.run(_fail_report(task_id, f"{type(exc).__name__}: {exc}"))
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user