feat(shipping-notice): 新增发货通知自动上传功能与候选资格评估
- 在环境配置中新增 SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED 选项,默认关闭,需显式开启以支持自动上传。 - 引入新的 pytest.ini 文件,增加测试标记以支持自动化测试。 - 删除不再使用的 seed_shipping_notice_agents.py 文件,简化代码库。 - 更新相关 API,增强发货通知与候选资格评估功能,支持多种筛选条件。 - 增强文档与代码注释,反映新的业务逻辑与功能要求。
This commit is contained in:
1 parent
cef3d5b26a
commit
3a9fbac2fc
226 files changed
+25010
-2098
No files matched your search
@@ -4,9 +4,9 @@ services/shipping_notice/queue_service.py
|
||||
用途:货代发货后台任务队列适配层。
|
||||
依赖:app.jobs.queue、jobs.types、batch_orchestrator、intake_parse_workflow、
|
||||
order_extraction_run_service / document_layout.lifecycle(超时回收同步领域与 Workflow)。
|
||||
逻辑:发货通知写入通用 jobs;worker 领取 RUN/PARSE;超时回收时 PARSE Job
|
||||
经 sync_intake_after_parse_job_recovery 同步 Intake,避免永久 parsing;
|
||||
订单抽取/版面回收同步 WorkflowItem,避免永久 layout_parsing/extracting。
|
||||
逻辑:发货通知写入通用 jobs;enqueue 支持 commit=False 与业务同事务;
|
||||
worker 领取 RUN/PARSE;超时回收时 PARSE Job 经 sync_intake_after_parse_job_recovery
|
||||
同步 Intake;订单抽取/版面回收同步 WorkflowItem。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -32,8 +32,29 @@ def shipping_task_execution_mode() -> str:
|
||||
return str(current_app.config.get('SHIPPING_NOTICE_TASK_EXECUTION_MODE', 'worker') or 'worker').strip().lower()
|
||||
|
||||
|
||||
def enqueue_shipping_notice_job(*, task_no: str, created_by_id: int | None = None, batch_no: str | None = None) -> tuple[bool, str]:
|
||||
"""持久化一条单票发货后台任务;不再复用 kb_jobs。"""
|
||||
def enqueue_shipping_notice_job(
|
||||
*,
|
||||
task_no: str,
|
||||
created_by_id: int | None = None,
|
||||
batch_no: str | None = None,
|
||||
commit: bool = True,
|
||||
) -> tuple[bool, str]:
|
||||
"""
|
||||
持久化一条单票发货后台任务;不再复用 kb_jobs。
|
||||
|
||||
核心逻辑:写入 shipping_notice_run Job;sync 模式在 commit=True 时当场执行,
|
||||
commit=False 时仅 flush 入队,由调用方与业务行同事务提交后再执行(避免未提交任务被推进)。
|
||||
|
||||
Args:
|
||||
task_no: 发货任务号。
|
||||
created_by_id: 创建人。
|
||||
batch_no: 可选批次号。
|
||||
commit: False 时与业务同事务提交;此时 sync 模式返回 queued_sync_pending:<job_id>。
|
||||
|
||||
Returns:
|
||||
(ok, result_token);result_token 为 queued_for_worker / queued_manual /
|
||||
queued_sync_pending:<id> 或 sync 执行结果状态。
|
||||
"""
|
||||
normalized_task_no = str(task_no or '').strip().upper()
|
||||
if not normalized_task_no:
|
||||
return False, 'task_no is required'
|
||||
@@ -49,9 +70,13 @@ def enqueue_shipping_notice_job(*, task_no: str, created_by_id: int | None = Non
|
||||
created_by_id=created_by_id,
|
||||
message='等待后台处理发货任务',
|
||||
max_attempts=int(current_app.config.get('SHIPPING_NOTICE_JOB_MAX_ATTEMPTS', 3) or 3),
|
||||
commit=commit,
|
||||
)
|
||||
|
||||
if shipping_task_execution_mode() == 'sync':
|
||||
# [STEP] 同事务入队时延后执行,避免读到未提交的 Task。
|
||||
if not commit:
|
||||
return True, f'queued_sync_pending:{int(job_id)}'
|
||||
ok, result = run_shipping_notice_job({'job_id': job_id})
|
||||
return ok, result
|
||||
if shipping_task_execution_mode() in ('worker', 'rq'):
|
||||
@@ -203,6 +228,7 @@ def claim_next_shipping_notice_job() -> Job | None:
|
||||
JobType.SHIPPING_NOTICE_PARSE,
|
||||
JobType.SHIPPING_ORDER_EXTRACTION,
|
||||
JobType.SHIPPING_DOCUMENT_LAYOUT,
|
||||
JobType.SHIPPING_PROCESS_GATE,
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user