Compare commits
2 Commits
70f518a1c3
...
1093256de6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1093256de6 | ||
|
|
0c51a41cfc |
@@ -388,6 +388,40 @@ def ingest(site=None):
|
||||
return total
|
||||
|
||||
|
||||
def ingest_task(site, kind):
|
||||
"""按 (site, kind) 入库本次刚下载的文件(幂等 UPSERT),返回总条数。
|
||||
与 ingest(site) 的区别:只入本次刷新的那一类,避免重读写另一类文件(同步钩子里减少阻塞)。
|
||||
kind 路由:
|
||||
expected/actual 各入其列;
|
||||
undelivered 百世 入未到;
|
||||
undelivered 4 站 _site_undelivered_handler 内部连带下了 expected+actual,故入两者;
|
||||
__compare__ / 其它组合 返回 0。
|
||||
"""
|
||||
if site == "__compare__":
|
||||
return 0
|
||||
# 百世无应到/实到(只有站点直供的未到);非 undelivered 直接返回 0,避免
|
||||
# _ingest_expected/_ingest_actual 走到 _site_cfg(百世)=None 而 TypeError。
|
||||
if site == "百世" and kind != "undelivered":
|
||||
return 0
|
||||
dates = _read_business_dates()
|
||||
total = 0
|
||||
with _connect(_load_pg_config()["dbname"]) as conn:
|
||||
with conn.cursor() as cur:
|
||||
if kind == "expected":
|
||||
total += _ingest_expected(cur, site, dates.get(site))
|
||||
elif kind == "actual":
|
||||
total += _ingest_actual(cur, site)
|
||||
elif kind == "undelivered":
|
||||
if site == "百世":
|
||||
total += _ingest_undelivered_baishi(cur)
|
||||
else: # 顺心/中通/韵达/安能
|
||||
total += _ingest_expected(cur, site, dates.get(site))
|
||||
total += _ingest_actual(cur, site)
|
||||
# 其它组合(如 百世/expected,正常不经钩子触发):防御性返回 0
|
||||
conn.commit()
|
||||
return total
|
||||
|
||||
|
||||
# ============================== 命令行 ==============================
|
||||
|
||||
|
||||
@@ -404,6 +438,15 @@ def main():
|
||||
create_database()
|
||||
init_schema()
|
||||
ingest()
|
||||
elif cmd == "ingest-one":
|
||||
kind = sys.argv[3] if len(sys.argv) > 3 else None
|
||||
if not site or kind not in ("expected", "actual", "undelivered"):
|
||||
print(
|
||||
"用法: python -m inbound_verify.store ingest-one <site> <expected|actual|undelivered>"
|
||||
)
|
||||
sys.exit(1)
|
||||
total = ingest_task(site, kind)
|
||||
print(f">> [ingest-one] {site}/{kind} 入库 {total} 条")
|
||||
else:
|
||||
print(__doc__)
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user