feat(freight-rpa): 批次R解耦编排层并切换 onhand/inbound 契约
将 RPA 编排收编至 freight_rpa,回调迁 /api/freight-rpa/*。 共享目录与 Worker 契约一次切换至 onhand/inbound/upload, 并补 outbound 骨架与 tt16 排程 job key 迁移。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
bf3154033b
commit
ffc0d4a430
147 files changed
+4221
-2678
No files matched your search
@@ -69,7 +69,7 @@ def recover_stale_waiting_source_jobs() -> int:
|
||||
from flask import current_app
|
||||
|
||||
try:
|
||||
timeout = max(60, int(current_app.config.get('FREIGHT_RPA_RECEIPT_TIMEOUT_SECONDS', 900)))
|
||||
timeout = max(60, int(current_app.config.get('FREIGHT_RPA_INBOUND_TIMEOUT_SECONDS', 900)))
|
||||
except (TypeError, ValueError):
|
||||
timeout = 900
|
||||
cutoff = datetime.utcnow() - timedelta(seconds=timeout)
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
复用货代 ShippingReceiptReport trigger 链路,shipping_notice 域术语保留),不创建排程。
|
||||
按来源取 ShippingInventorySource + ShippingReceiptReportConfig + rpa_profile,
|
||||
先落 RPA 单元运行行(awaiting_rpa,回调按 callback_id 查库可达),
|
||||
再装配入站 trigger unit 并调用 write_receipt_export_batch_trigger 原子写 trigger。
|
||||
依赖:write_receipt_export_batch_trigger(默认 writer,shipping_notice 域)、models、db。
|
||||
再装配入站 trigger unit 并调用 write_inbound_export_batch_trigger 原子写 trigger。
|
||||
依赖:write_inbound_export_batch_trigger(默认 writer,freight_rpa.inbound.trigger_io)、models、db。
|
||||
逻辑:list_inbound_capable_source_codes 供排程 source_codes 留空时的缺省范围;
|
||||
一源一单元,query_parameters 原样下发;来源停用/ShippingReceiptReportConfig 缺失/rpa_profile 缺失时
|
||||
fail-closed;写 trigger 失败把单元行标 failed 并 commit。
|
||||
@@ -19,7 +19,11 @@ import uuid
|
||||
from datetime import datetime
|
||||
from typing import Any, Callable
|
||||
|
||||
from app.services.shipping_notice.receipt_rpa import write_receipt_export_batch_trigger
|
||||
from app.services.freight_rpa.inbound.trigger_io import (
|
||||
ACTION_INBOUND_EXPORT_BATCH,
|
||||
SCHEMA,
|
||||
write_inbound_export_batch_trigger,
|
||||
)
|
||||
|
||||
RouteTriggerWriter = Callable[..., str | None]
|
||||
|
||||
@@ -105,7 +109,7 @@ def trigger_inbound_rpa(
|
||||
source_code: 来源实例编码。
|
||||
business_date: 业务日期。
|
||||
reason: 触发原因(写入 trigger)。
|
||||
writer: 触发写者;缺省复用 write_receipt_export_batch_trigger。
|
||||
writer: 触发写者;缺省复用 write_inbound_export_batch_trigger。
|
||||
Returns:
|
||||
{"ok": True, "callback_id": ..., "trigger_path": ...} 或
|
||||
{"ok": False, "error_code": ...}(配置缺失 / 触发目录不可用)。
|
||||
@@ -136,10 +140,10 @@ def trigger_inbound_rpa(
|
||||
|
||||
# [STEP 2] 原子写 trigger;目录不可用则单元标 failed(fail-closed,不留永久 awaiting)。
|
||||
run_no = f"TRIG-{source_code}-{uuid.uuid4().hex[:8].upper()}"
|
||||
writer_fn = writer or write_receipt_export_batch_trigger
|
||||
writer_fn = writer or write_inbound_export_batch_trigger
|
||||
path = writer_fn(run_no, [unit_payload], payload={
|
||||
'schema_version': 'shipping_receipt_rpa.v1',
|
||||
'action': 'receipt_export_batch',
|
||||
'schema_version': SCHEMA,
|
||||
'action': ACTION_INBOUND_EXPORT_BATCH,
|
||||
'source_code': source_code,
|
||||
'business_date': business_date,
|
||||
'reason': reason,
|
||||
@@ -171,14 +175,14 @@ def trigger_inbound_rpa_batch(
|
||||
|
||||
核心逻辑:逐来源装配 unit(来源级隔离——配置缺失/停用跳过并记录,不炸整批;
|
||||
parse_failed 先本地重解析,恢复 ready 则不触发 RPA),有效 units 先各落一行
|
||||
RPA 单元运行行再一次性 write_receipt_export_batch_trigger 原子落盘。
|
||||
RPA 单元运行行再一次性 write_inbound_export_batch_trigger 原子落盘。
|
||||
Worker 对单文件按 profile 分组共享一次浏览器会话串行导出,避免逐来源开/关浏览器。
|
||||
|
||||
Args:
|
||||
source_codes: 来源实例编码列表(去重保序;空串自动剔除)。
|
||||
business_date: 业务日期。
|
||||
reason: 触发原因(写入 trigger payload)。
|
||||
writer: 触发写者;缺省复用 write_receipt_export_batch_trigger。
|
||||
writer: 触发写者;缺省复用 write_inbound_export_batch_trigger。
|
||||
|
||||
Returns:
|
||||
{"ok": True/False, "triggered": bool, "results": [...], "trigger_path"?/「error_code」?}。
|
||||
@@ -247,10 +251,10 @@ def trigger_inbound_rpa_batch(
|
||||
|
||||
# [STEP 3] 一个 batch trigger 原子落盘;目录不可用则本批单元全部标 failed(不留永久 awaiting)。
|
||||
run_no = f"TRIG-BATCH-{uuid.uuid4().hex[:8].upper()}"
|
||||
writer_fn = writer or write_receipt_export_batch_trigger
|
||||
writer_fn = writer or write_inbound_export_batch_trigger
|
||||
path = writer_fn(run_no, unit_payloads, payload={
|
||||
'schema_version': 'shipping_receipt_rpa.v1',
|
||||
'action': 'receipt_export_batch',
|
||||
'schema_version': SCHEMA,
|
||||
'action': ACTION_INBOUND_EXPORT_BATCH,
|
||||
'business_date': business_date,
|
||||
'reason': reason,
|
||||
'source_codes': [payload['source_code'] for payload in unit_payloads],
|
||||
|
||||
Reference in new issue
Block a user