From c6ad6a0ca27cabc0eb7f6eff5ac14d7620524618 Mon Sep 17 00:00:00 2001 From: Misaka Date: Fri, 31 Jul 2026 20:25:52 +0800 Subject: [PATCH] fix(runtime): ingest before db_compare so first-run/force reads fresh data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DB 比对发生在入库之前,导致首次/force 时 PG 无当天数据,比对返回 None、不产出 Excel。在 _site_undelivered_handler 下载成功后、比对前,前置 _record_business_date + ingest_task,使比对能读到本次下载的数据。dispatch_task 后置 _persist_to_db 保持不变(对 undelivered 幂等重复一次,安全)。 四站真机验证通过(中通/韵达/安能 + 顺心):前置入库日志均出现在 db_compare 之前,force 首跑即产出 Excel。 Co-Authored-By: Claude --- inbound_verify/runtime.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/inbound_verify/runtime.py b/inbound_verify/runtime.py index 5943b23..27c7195 100644 --- a/inbound_verify/runtime.py +++ b/inbound_verify/runtime.py @@ -493,6 +493,23 @@ def _site_undelivered_handler(site): os.remove(stale) return False + # ── 先入库再比对(修复时序:比对须读到本次下载的数据, + # 否则首次/force 时 PG 无当天数据,比对返回 None、不产出 Excel)── + try: + _record_business_date(site, "undelivered", date) + except Exception: + pass + try: + from inbound_verify import store # 懒导入,避免成环 + + if store.ingest_enabled(): + store.ingest_task( + site, "undelivered" + ) # 4 站 = ingest expected + actual + print(f">> [入库] {site} 前置入库完成") + except Exception as e: + print(f">> [入库] {site} 前置入库失败(不影响比对尝试): {e}") + # ── DB 比对(替代旧 Excel 比对)── try: from inbound_verify import db_compare # 懒导入,避免成环