feat(shipping-notice): 新增发货通知重复检测与处理接口,支持重复决策保存与重新执行检测
This commit is contained in:
1 parent
729546a7b7
commit
ceb49461e8
72 files changed
+14270
-460
No files matched your search
@@ -2,8 +2,9 @@
|
||||
services/shipping_notice/queue_service.py
|
||||
|
||||
用途:货代发货后台任务队列适配层。
|
||||
依赖:app.jobs.queue、jobs.types、shipping_notice.batch_orchestrator。
|
||||
逻辑:发货通知只写入通用 jobs 表,worker 通过 Job Runner 消费后执行单票编排。
|
||||
依赖:app.jobs.queue、jobs.types、batch_orchestrator、intake_parse_workflow。
|
||||
逻辑:发货通知写入通用 jobs;worker 领取 RUN/PARSE;超时回收时 PARSE Job
|
||||
经 sync_intake_after_parse_job_recovery 同步 Intake,避免永久 parsing。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -110,19 +111,48 @@ def _requeue_external_wait_job(task_no: str, *, job: Job | None = None) -> None:
|
||||
|
||||
|
||||
def recover_stale_shipping_notice_jobs() -> tuple[int, str]:
|
||||
"""兼容旧调用:回收通用 jobs 表里超时的发货任务,并顺带消费 RPA callback cleanup 队列。"""
|
||||
"""
|
||||
回收通用 jobs 表里超时的发货任务,并顺带消费 RPA callback cleanup 队列。
|
||||
|
||||
核心逻辑:单票编排与预解析分超时配置回收;预解析 Job 回收同事务同步 Intake,
|
||||
避免 Job 已 requeue/failed 而 Intake 永久 parsing。
|
||||
"""
|
||||
from app.jobs.queue import recover_stale_jobs
|
||||
from app.services.shipping_notice.intake_parse_workflow import (
|
||||
sync_intake_after_parse_job_recovery,
|
||||
)
|
||||
from app.services.shipping_notice.inventory_rpa_callback_cleanup import (
|
||||
recover_pending_rpa_callback_cleanup_jobs,
|
||||
)
|
||||
|
||||
timeout_sec = float(current_app.config.get('SHIPPING_NOTICE_JOB_RUNNING_TIMEOUT_SECONDS', 300))
|
||||
count = recover_stale_jobs(domain=SHIPPING_NOTICE_JOB_DOMAIN, timeout_seconds=timeout_sec)
|
||||
run_timeout = float(
|
||||
current_app.config.get('SHIPPING_NOTICE_JOB_RUNNING_TIMEOUT_SECONDS', 300) or 300
|
||||
)
|
||||
parse_timeout = float(
|
||||
current_app.config.get('SHIPPING_NOTICE_PARSE_WORKER_TIMEOUT_SECONDS', 300) or 300
|
||||
)
|
||||
run_count = recover_stale_jobs(
|
||||
domain=SHIPPING_NOTICE_JOB_DOMAIN,
|
||||
timeout_seconds=run_timeout,
|
||||
job_type=JobType.SHIPPING_NOTICE_RUN,
|
||||
)
|
||||
parse_count = recover_stale_jobs(
|
||||
domain=SHIPPING_NOTICE_JOB_DOMAIN,
|
||||
timeout_seconds=parse_timeout,
|
||||
job_type=JobType.SHIPPING_NOTICE_PARSE,
|
||||
on_recovered=sync_intake_after_parse_job_recovery,
|
||||
)
|
||||
count = int(run_count) + int(parse_count)
|
||||
cleanup_count, cleanup_warnings = recover_pending_rpa_callback_cleanup_jobs()
|
||||
if cleanup_warnings:
|
||||
logger.warning('rpa callback cleanup warnings: %s', '; '.join(cleanup_warnings[:5]))
|
||||
if count:
|
||||
logger.warning('recovered %s stale shipping_notice job(s)', count)
|
||||
logger.warning(
|
||||
'recovered %s stale shipping_notice job(s) (run=%s parse=%s)',
|
||||
count,
|
||||
run_count,
|
||||
parse_count,
|
||||
)
|
||||
if cleanup_count:
|
||||
logger.info('processed %s rpa callback cleanup job(s)', cleanup_count)
|
||||
parts = []
|
||||
|
||||
Reference in new issue
Block a user