feat: 累积功能变更 — 聊天集成、租户管理、小程序更新、ETL 增强、迁移脚本
包含多个会话的累积代码变更: - backend: AI 聊天服务、触发器调度、认证增强、WebSocket、调度器最小间隔 - admin-web: ETL 状态页、任务管理、调度配置、登录优化 - miniprogram: 看板页面、聊天集成、UI 组件、导航更新 - etl: DWS 新任务(finance_area_daily/board_cache)、连接器增强 - tenant-admin: 项目初始化 - db: 19 个迁移脚本(etl_feiqiu 11 + zqyy_app 8) - packages/shared: 枚举和工具函数更新 - tools: 数据库工具、报表生成、健康检查 - docs: PRD/架构/部署/合约文档更新 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
83
apps/backend/app/routers/internal_events.py
Normal file
83
apps/backend/app/routers/internal_events.py
Normal file
@@ -0,0 +1,83 @@
|
||||
# AI_CHANGELOG
|
||||
# - 2026-03-29 | Prompt: DWS_TASK_ENGINE ETL 任务 | 新建文件。
|
||||
# 提供 POST /api/internal/run-job 端点,供 ETL 按 job_name 执行
|
||||
# biz.trigger_jobs 中的任务。Internal-Token 认证。
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
内部任务执行 API — ETL/内部服务调用入口。
|
||||
|
||||
端点:
|
||||
- POST /api/internal/run-job — 按 job_name 执行 biz.trigger_jobs 中的任务
|
||||
|
||||
认证方式:Authorization: Internal-Token {token}
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from app.auth.internal_token import verify_internal_token
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
router = APIRouter(prefix="/api/internal", tags=["internal-events"])
|
||||
|
||||
|
||||
class RunJobByNameRequest(BaseModel):
|
||||
"""按 job_name 执行任务的请求体。"""
|
||||
job_name: str = Field(..., description="任务名称,如 recall_completion_check")
|
||||
|
||||
|
||||
class RunJobByNameResponse(BaseModel):
|
||||
"""执行结果。"""
|
||||
success: bool
|
||||
message: str
|
||||
job_name: str
|
||||
|
||||
|
||||
@router.post("/run-job", response_model=RunJobByNameResponse)
|
||||
async def run_job_by_name_endpoint(
|
||||
body: RunJobByNameRequest,
|
||||
_token: str = Depends(verify_internal_token),
|
||||
) -> RunJobByNameResponse:
|
||||
"""按 job_name 查找并执行 biz.trigger_jobs 中的任务。
|
||||
|
||||
ETL DWS_TASK_ENGINE 任务通过此端点按顺序执行后端任务引擎的各个步骤。
|
||||
"""
|
||||
from app.database import get_connection
|
||||
from app.services.trigger_scheduler import run_job_by_id
|
||||
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"SELECT id FROM biz.trigger_jobs WHERE job_name = %s",
|
||||
(body.job_name,),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
if not row:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=f"任务 '{body.job_name}' 不存在",
|
||||
)
|
||||
|
||||
job_id = row[0]
|
||||
result = run_job_by_id(job_id)
|
||||
|
||||
logger.info(
|
||||
"内部任务执行: job_name=%s, success=%s",
|
||||
body.job_name, result.get("success"),
|
||||
)
|
||||
return RunJobByNameResponse(
|
||||
success=result.get("success", False),
|
||||
message=result.get("message", ""),
|
||||
job_name=body.job_name,
|
||||
)
|
||||
Reference in New Issue
Block a user