feat(queue): 添加旧知识库任务入队兼容入口

- 增加 enqueue_kb_job 和 enqueue_clean_job 函数以支持旧 KB 清洗任务入队
- 在 enqueue 函数中处理 KB_CLEAN 和 KB_DIFY_SYNC 类型的任务
- 引入 ValidationError 以处理 job_id 缺失的情况

feat(shipping_notice): 更新库存 RPA 工作流逻辑
- 修改 ensure_inventory_via_rpa 函数以支持手动重试逻辑
- 优化库存导出触发和状态更新的消息提示

fix(i18n): 更新任务未找到的提示信息
- 修改中文和英文提示,明确用户操作要求

feat(shipping_notice): 增强任务解析逻辑
- 添加缺失 Reservation ID 的检查,阻止任务进入确认阶段
- 更新 get_task_status 函数以处理多票会话的任务解析
This commit is contained in:
hugo committed 2026-06-30 21:00:25 +08:00
1 parent eb0466245b
commit 4cd987eef6
45 files changed
+2748 -1406

No files matched your search

+39 -3
View File
@@ -1,9 +1,9 @@
"""
backend/app/jobs/queue.py
用途:通用后台任务入队、领取与完成状态管理。
依赖:models.Job、jobs.types、Flask app.config。
逻辑:业务服务调用 enqueue 写入 jobs;worker 调用 claim/finish/fail 完成执行闭环。
用途:通用后台任务入队、领取与完成状态管理,并保留旧 KB 入队兼容入口。
依赖:models.Job、jobs.types、Flask app.config、knowledge_cleaning 队列适配层。
逻辑:业务服务调用 enqueue 写入 jobs;旧 KB 清洗入口委托 legacy KbJob 队列;worker 调用 claim/finish/fail 完成执行闭环。
"""
from __future__ import annotations
@@ -15,6 +15,7 @@ from flask import current_app
from sqlalchemy.exc import OperationalError
from app import db
from app.core.errors import ValidationError
from app.jobs.types import JobType
from app.models import Job
@@ -65,6 +66,32 @@ def _find_shipping_notice_job_id(task_no: str) -> int | None:
return None
def enqueue_kb_job(job_id: int) -> tuple[bool, str]:
"""
兼容旧知识库后台任务入队入口。
Args:
job_id: KbJob 主键;由清洗、路径上传、Dify 同步等知识库流程传入。
Returns:
(是否接受入队, 队列状态说明)。
"""
from app.services.knowledge_cleaning.queue_service import enqueue_kb_job as _enqueue_kb_job
return _enqueue_kb_job(job_id)
def enqueue_clean_job(job_id: int) -> tuple[bool, str]:
"""
兼容旧清洗任务入队入口。
Args:
job_id: clean 类型 KbJob 主键。
Returns:
(是否接受入队, 队列状态说明)。
"""
return enqueue_kb_job(job_id)
def enqueue(
job_type: JobType | str,
payload: dict[str, Any],
@@ -96,6 +123,15 @@ def enqueue(
scheduled_at: 未来时间则延迟到该时间后才可被 worker 领取。
"""
normalized_type = _normalize_job_type(job_type)
if normalized_type in {JobType.KB_CLEAN.value, JobType.KB_DIFY_SYNC.value}:
raw_job_id = (payload or {}).get("job_id") if isinstance(payload, dict) else None
if not raw_job_id:
raise ValidationError("job_id is required")
ok, message_text = enqueue_kb_job(int(raw_job_id))
if not ok:
raise ValidationError(message_text or "enqueue kb job failed")
return int(raw_job_id)
normalized_domain = str(domain or "").strip() or "default"
normalized_ref = str(business_ref or correlation_id or "").strip() or None
if not normalized_type: