refactor: 统一 Redis 连接管理,改用 RedisService

- App 启动时初始化 RedisService,关闭时释放连接
- Celery worker 通过 worker_process_init 钩子初始化 Redis
- Agent 端点改用 RedisService 替代直接创建连接
- Celery task 改为 async def,使用统一连接
- 删除无用的 infra 模块和 core/http/models
- 日志脱敏,不记录 Redis 密码
- 初始化失败时 fail-fast
- 异常发布添加二级保护
This commit is contained in:
qzl
2026-03-06 16:09:15 +08:00
parent c5ccfc4b88
commit 2c59fe5ee2
14 changed files with 101 additions and 150 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ def test_mobile_health_e2e() -> None:
base_url=f"http://{host}:{port}"
)
try:
response = request_context.get("/api/v1/health")
response = request_context.get("/health")
assert response.status == 200
body = response.json()
assert body["status"] == "ok"
@@ -15,16 +15,6 @@ def test_app_health_returns_envelope() -> None:
assert body["status"] == "ok"
def test_mobile_router_health_returns_envelope() -> None:
client = TestClient(app)
response = client.get("/api/v1/health")
assert response.status_code == 200
body = response.json()
assert body["status"] == "ok"
def test_not_found_returns_error_envelope() -> None:
client = TestClient(app)
@@ -15,15 +15,16 @@ class _FakeResumeService:
return {"session_id": session_id, "tool_call_id": tool_call_id}
def test_run_agent_task_emits_started_runtime_and_finished_events() -> None:
@pytest.mark.asyncio
async def test_run_agent_task_emits_started_runtime_and_finished_events() -> None:
session_id = "00000000-0000-0000-0000-000000000001"
events: list[str] = []
def _publish(event_type: str, payload: dict[str, object]) -> None:
async def _publish(event_type: str, payload: dict[str, object]) -> None:
del payload
events.append(event_type)
result = run_agent_task(
result = await run_agent_task(
{
"command": "run",
"session_id": session_id,
@@ -38,7 +39,8 @@ def test_run_agent_task_emits_started_runtime_and_finished_events() -> None:
assert events == ["RUN_STARTED", "RUNTIME_EVENT", "RUN_FINISHED"]
def test_run_agent_task_emits_error_event_on_exception() -> None:
@pytest.mark.asyncio
async def test_run_agent_task_emits_error_event_on_exception() -> None:
session_id = "00000000-0000-0000-0000-000000000001"
class _BrokenRunService(_FakeRunService):
@@ -48,12 +50,12 @@ def test_run_agent_task_emits_error_event_on_exception() -> None:
events: list[str] = []
def _publish(event_type: str, payload: dict[str, object]) -> None:
async def _publish(event_type: str, payload: dict[str, object]) -> None:
del payload
events.append(event_type)
with pytest.raises(RuntimeError):
run_agent_task(
await run_agent_task(
{
"command": "run",
"session_id": session_id,