feat(file-check-tool): 实现对话触发检核无待检资料时展示100%完成进度卡
更新工具API的OpenAPI定义,新增NoDataResponse结构体;修改预检与响应逻辑,无待检资料时创建已完成的空批次并绑定当前对话;同步更新相关文档并补充测试用例验证流程正确性。
This commit is contained in:
1 parent
2878a6998e
commit
e6a44df260
7 files changed
+177
-16
No files matched your search
@@ -345,12 +345,26 @@ def _bind_queried_run_to_turn(run: ScheduleRun, data: dict) -> None:
|
||||
attach_run_to_turn(turn_id, int(run.id))
|
||||
|
||||
|
||||
def _build_no_data_response(task: ScheduleTask) -> dict:
|
||||
"""无待检资料时直接返回提示,不创建批次也不绑定 run_id。"""
|
||||
def _build_no_data_response(task: ScheduleTask, run: ScheduleRun) -> dict:
|
||||
"""
|
||||
组装无待检资料的 Tool 响应,并返回本轮已完成的空批次。
|
||||
|
||||
【AI 触发时机】:用户要求立即执行文件检核,但预检未发现待检资料时调用。
|
||||
核心逻辑:保留 no_data_to_check 供 Chatflow 回复无资料提示,同时携带已绑定的 Run,
|
||||
使前端能在该轮消息下展示总数 0、进度 100% 的完成进度卡。
|
||||
|
||||
Args:
|
||||
task: 当前检核任务。
|
||||
run: 已持久化并绑定当前对话的成功空批次。
|
||||
|
||||
Returns:
|
||||
dict: 包含 no_data_to_check、任务信息和 Run 摘要的 HTTP 200 响应体。
|
||||
"""
|
||||
return {
|
||||
"ok": False,
|
||||
"error_code": "no_data_to_check",
|
||||
"message": "目前没有资料需要检核",
|
||||
"run": _serialize_tool_run(run),
|
||||
"task": {
|
||||
"task_id": task.id,
|
||||
"task_name": task.name,
|
||||
@@ -380,8 +394,8 @@ def _precheck_no_data(task: ScheduleTask) -> dict | None:
|
||||
"""
|
||||
启动前预检当前任务是否存在待检资料。
|
||||
|
||||
核心逻辑:仅在数据库型检核任务上做轻量预检;若结果为空,则直接返回 no_data_to_check,
|
||||
避免创建空批次并向 ChatLog 回写 run_id。数据源连接失败时抛 503 data_source_unavailable。
|
||||
核心逻辑:仅在数据库型检核任务上做轻量预检;若结果为空,则返回 no_data_to_check 标识,
|
||||
由启动入口创建并绑定完成态的 0 笔 Run。数据源连接失败时抛 503 data_source_unavailable。
|
||||
"""
|
||||
if str(getattr(task, "data_source_type", "") or "database").lower() != "database":
|
||||
return None
|
||||
@@ -405,7 +419,52 @@ def _precheck_no_data(task: ScheduleTask) -> dict | None:
|
||||
|
||||
if rows:
|
||||
return None
|
||||
return _build_no_data_response(task)
|
||||
return {
|
||||
"ok": False,
|
||||
"error_code": "no_data_to_check",
|
||||
"message": "目前没有资料需要检核",
|
||||
}
|
||||
|
||||
|
||||
def _create_no_data_run(task: ScheduleTask, data: dict) -> ScheduleRun:
|
||||
"""
|
||||
为预检为空的立即执行请求创建并绑定已完成的 0 笔检核批次。
|
||||
|
||||
【AI 触发时机】:run_file_check 收到 no_data_to_check 预检结果时调用。
|
||||
核心逻辑:不启动后台 worker,仅写入 success Run 与对话绑定;完成态空批次由工作区进度接口
|
||||
序列化为 100%,让用户明确知道本次检核已经结束且没有待处理资料。
|
||||
|
||||
Args:
|
||||
task: 已解析的文件检核任务。
|
||||
data: Tool 请求及对话绑定上下文。
|
||||
|
||||
Returns:
|
||||
ScheduleRun: 已提交且已绑定当前对话的成功空批次。
|
||||
"""
|
||||
finished_at = datetime.utcnow()
|
||||
run = ScheduleRun(
|
||||
run_no=_generate_run_no(),
|
||||
schedule_task_id=task.id,
|
||||
trigger_type="dify_chatflow",
|
||||
started_at=finished_at,
|
||||
finished_at=finished_at,
|
||||
duration_ms=0,
|
||||
status="success",
|
||||
total_count=0,
|
||||
success_count=0,
|
||||
failed_count=0,
|
||||
skipped_count=0,
|
||||
api_request_json={
|
||||
"trigger_source": data.get("trigger_source") or "dify_chatflow",
|
||||
"conversation_id": data.get("conversation_id"),
|
||||
},
|
||||
response_summary_json={"errors": [], "no_data": True},
|
||||
)
|
||||
db.session.add(run)
|
||||
db.session.commit()
|
||||
_record_run_bind(run, data)
|
||||
db.session.commit()
|
||||
return run
|
||||
|
||||
|
||||
@file_check_bp.route("/tools/tasks/run", methods=["POST"])
|
||||
@@ -445,16 +504,18 @@ def run_file_check():
|
||||
|
||||
no_data_response = _precheck_no_data(task)
|
||||
if no_data_response:
|
||||
run = _create_no_data_run(task, data)
|
||||
lock_ms = int((time.perf_counter() - lock_started) * 1000)
|
||||
total_ms = int((time.perf_counter() - perf_started) * 1000)
|
||||
current_app.logger.info(
|
||||
"[file-check-tool-perf] run_file_check outcome=no_data resolve_ms=%s lock_ms=%s total_ms=%s task_id=%s",
|
||||
"[file-check-tool-perf] run_file_check outcome=no_data resolve_ms=%s lock_ms=%s total_ms=%s task_id=%s run_id=%s",
|
||||
resolve_ms,
|
||||
lock_ms,
|
||||
total_ms,
|
||||
task.id,
|
||||
run.id,
|
||||
)
|
||||
return jsonify(no_data_response)
|
||||
return jsonify(_build_no_data_response(task, run))
|
||||
|
||||
run = ScheduleRun(
|
||||
run_no=_generate_run_no(),
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "启动成功;或已有 文件检核进行中,返回 ok=false/error_code=check_running",
|
||||
"description": "启动成功;已有检核进行中或预检无资料时返回 ok=false。预检无资料仍返回已完成的 0 笔 run,供前端展示 100% 进度。",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
@@ -94,6 +94,9 @@
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/CheckRunningResponse"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/NoDataResponse"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -641,6 +644,36 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"NoDataResponse": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"ok",
|
||||
"error_code",
|
||||
"message",
|
||||
"run",
|
||||
"task"
|
||||
],
|
||||
"properties": {
|
||||
"ok": {
|
||||
"type": "boolean",
|
||||
"example": false
|
||||
},
|
||||
"error_code": {
|
||||
"type": "string",
|
||||
"example": "no_data_to_check"
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"example": "目前没有资料需要检核"
|
||||
},
|
||||
"run": {
|
||||
"$ref": "#/components/schemas/RunDetail"
|
||||
},
|
||||
"task": {
|
||||
"$ref": "#/components/schemas/TaskSummary"
|
||||
}
|
||||
}
|
||||
},
|
||||
"GetRunResponse": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
||||
Reference in new issue
Block a user