feat: 详细日志(分页/映射/批次进度)+ Artifacts 摘要(sync-summary/verify-report)
This commit is contained in:
@@ -14,17 +14,21 @@ def sync_riin_records(raw_orders: list[Any], client: RiinDisClient, db: SyncDB)
|
||||
order_inputs: list[Any] = []
|
||||
order_meta: dict[str, tuple[str, Any]] = {} # raw.id -> (orderNo, createdAt)
|
||||
goods_failed = 0
|
||||
order_map_failed = 0
|
||||
|
||||
for raw in raw_orders:
|
||||
try:
|
||||
o = map_riin_order(raw)
|
||||
except Exception as err: # noqa: BLE001
|
||||
order_map_failed += 1
|
||||
print(f"[RIIN] 映射订单失败 {getattr(raw, 'platform_oid', '?')}: {err}")
|
||||
continue
|
||||
order_inputs.append(o)
|
||||
if raw.id:
|
||||
order_meta[raw.id] = (o.orderNo, o.createdAt)
|
||||
|
||||
print(f"[RIIN] 订单映射完成: 成功 {len(order_inputs)} / 失败 {order_map_failed} (共 {len(raw_orders)})")
|
||||
|
||||
goods_inputs: list[Any] = []
|
||||
if order_meta:
|
||||
goods_map = fetch_goods_concurrent(client, list(order_meta.keys()))
|
||||
@@ -38,6 +42,8 @@ def sync_riin_records(raw_orders: list[Any], client: RiinDisClient, db: SyncDB)
|
||||
except Exception as err: # noqa: BLE001
|
||||
print(f"[RIIN] 映射商品失败 order={order_no}: {err}")
|
||||
|
||||
print(f"[RIIN] 商品映射完成: {len(goods_inputs)} 条, 商品拉取失败订单 {goods_failed} 个")
|
||||
|
||||
stats = db.sync_orders_and_goods(order_inputs, goods_inputs)
|
||||
stats["orderCount"] = len(order_inputs)
|
||||
stats["goodsCount"] = len(goods_inputs)
|
||||
|
||||
@@ -11,7 +11,7 @@ from prefect import flow, task
|
||||
|
||||
from api.riin.models import OrderPageRequest
|
||||
from flows.riin._pipeline import sync_riin_records
|
||||
from flows.shared import SyncDB, create_riin_client
|
||||
from flows.shared import SyncDB, build_stats_rows, create_riin_client, emit_sync_summary
|
||||
|
||||
|
||||
def _split_order_nos(text: str) -> list[str]:
|
||||
@@ -52,6 +52,7 @@ def riin_by_orders_sync(order_nos: str) -> dict:
|
||||
raw = fetch_by_orders(nos)
|
||||
stats = upsert_records(raw)
|
||||
print(f"完成: 匹配 {len(raw)} | {stats}")
|
||||
emit_sync_summary("RIIN 指定单号同步", build_stats_rows("RIIN", stats, [("输入单号", len(nos)), ("匹配", len(raw))]))
|
||||
return {"inputCount": len(nos), "matchedCount": len(raw), **stats}
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@ from prefect import flow, task
|
||||
|
||||
from flows.riin._pipeline import sync_riin_records
|
||||
from flows.shared import (
|
||||
SyncDB, create_riin_client, fetch_riin_all_pages, floor_to_hour, format_date,
|
||||
SyncDB, build_stats_rows, create_riin_client, emit_sync_summary, fetch_riin_all_pages,
|
||||
floor_to_hour, format_date,
|
||||
)
|
||||
|
||||
|
||||
@@ -55,6 +56,7 @@ def riin_incremental_sync() -> dict:
|
||||
raw = extract_orders(params)
|
||||
stats = upsert_records(raw)
|
||||
print(f"完成: 订单 {stats['orderCount']} / 商品 {stats['goodsCount']}")
|
||||
emit_sync_summary("RIIN 增量同步", build_stats_rows("RIIN", stats, [("时间范围", f"{params['start_time']} ~ {params['end_time']}")]))
|
||||
return {"syncRange": {"from": params["start_time"], "to": params["end_time"]}, **stats}
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ from prefect import flow, task
|
||||
|
||||
from api.riin.models import OrderPageRequest
|
||||
from flows.riin._pipeline import sync_riin_records
|
||||
from flows.shared import SyncDB, create_riin_client, fetch_riin_all_pages, format_date
|
||||
from flows.shared import (
|
||||
SyncDB, build_stats_rows, create_riin_client, emit_sync_summary, fetch_riin_all_pages, format_date,
|
||||
)
|
||||
|
||||
|
||||
@task(retries=3, retry_delay_seconds=[3, 6, 9])
|
||||
@@ -70,6 +72,7 @@ def riin_order_sync(
|
||||
raw = extract_orders(params)
|
||||
stats = upsert_records(raw)
|
||||
print(f"完成: 订单 {stats['orderCount']} / 商品 {stats['goodsCount']} | {stats}")
|
||||
emit_sync_summary("RIIN 订单同步", build_stats_rows("RIIN", stats, [("时间范围", f"{order_date_begin} ~ {order_date_end}")]))
|
||||
return {"syncRange": {"from": order_date_begin, "to": order_date_end}, **stats}
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@ from prefect import flow, task
|
||||
|
||||
from flows.riin._pipeline import sync_riin_records
|
||||
from flows.shared import (
|
||||
SyncDB, create_riin_client, fetch_riin_all_pages, format_date, start_of_day,
|
||||
SyncDB, build_stats_rows, create_riin_client, emit_sync_summary,
|
||||
fetch_riin_all_pages, format_date, start_of_day,
|
||||
)
|
||||
|
||||
|
||||
@@ -49,6 +50,7 @@ def riin_recent_sync(recent_days: int = 7) -> dict:
|
||||
raw = extract_orders(params)
|
||||
stats = upsert_records(raw)
|
||||
print(f"完成: 订单 {stats['orderCount']} / 商品 {stats['goodsCount']}")
|
||||
emit_sync_summary("RIIN 近期同步", build_stats_rows("RIIN", stats, [("近N天", days), ("时间范围", f"{params['start_time']} ~ {params['end_time']}")]))
|
||||
return {"syncRange": {"from": params["start_time"], "to": params["end_time"]}, "recentDays": days, **stats}
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from prefect import flow, task
|
||||
|
||||
from api.riin.models import OrderPageRequest
|
||||
from flows.riin._pipeline import sync_riin_records
|
||||
from flows.shared import SyncDB, create_riin_client
|
||||
from flows.shared import SyncDB, build_stats_rows, create_riin_client, emit_sync_summary
|
||||
|
||||
RIIN_FINISHED_STATUSES = ["已退款", "已关闭", "已发货"]
|
||||
ORDER_BATCH = 500
|
||||
@@ -51,6 +51,7 @@ def riin_refresh_pending() -> dict:
|
||||
raw = fetch_pending(order_nos)
|
||||
stats = upsert_records(raw)
|
||||
print(f"完成: 匹配 {len(raw)} | {stats}")
|
||||
emit_sync_summary("RIIN 刷新未完结", build_stats_rows("RIIN", stats, [("未完结订单", len(order_nos)), ("匹配", len(raw))]))
|
||||
return {"pendingCount": len(order_nos), "matchedCount": len(raw), **stats}
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ from prefect import flow, task
|
||||
from api.riin.models import OrderPageRequest
|
||||
from flows.riin._pipeline import sync_riin_records
|
||||
from flows.shared import (
|
||||
SyncDB, create_riin_client, fetch_riin_all_pages, format_date, start_of_day,
|
||||
SyncDB, create_riin_client, emit_verify_report, fetch_riin_all_pages, format_date, start_of_day,
|
||||
)
|
||||
|
||||
RIIN_COUNT_STATUS_MAP = {
|
||||
@@ -96,7 +96,7 @@ def riin_verify(mode: str = "recent", recent_days: int = 1, date_range: str | No
|
||||
print(f"[核验 {day_str}] 远程 {remote_total} 本地 {sum(local_counts.values())}"
|
||||
+ (f" 差异 {diff}" if has_diff else " 一致,跳过"))
|
||||
if not has_diff:
|
||||
day_reports.append({"date": day_str, "diff": diff, "ok": True})
|
||||
day_reports.append({"date": day_str, "remote": remote_total, "local": sum(local_counts.values()), "diff": diff, "ok": True})
|
||||
continue
|
||||
|
||||
days_with_diff += 1
|
||||
@@ -111,11 +111,13 @@ def riin_verify(mode: str = "recent", recent_days: int = 1, date_range: str | No
|
||||
totals["ordersUpdated"] += stats["ordersUpdated"]
|
||||
totals["goodsAdded"] += stats["goodsCreated"]
|
||||
totals["goodsUpdated"] += stats["goodsUpdated"]
|
||||
day_reports.append({"date": day_str, "diff": diff, "ok": False,
|
||||
day_reports.append({"date": day_str, "remote": remote_total, "local": sum(local_counts.values()), "diff": diff, "ok": False,
|
||||
"orders": stats["orderCount"], "goods": stats["goodsCount"]})
|
||||
finally:
|
||||
client.close()
|
||||
|
||||
print(f"[核验汇总] 共 {len(days)} 天 / 有差异 {days_with_diff} 天 / {totals}")
|
||||
emit_verify_report("RIIN 数据核验", day_reports, totals, len(days), days_with_diff)
|
||||
return {
|
||||
"verifyReport": {"days": day_reports, "summary": {"totalDays": len(days), "daysWithDiff": days_with_diff, **totals}},
|
||||
"syncRange": {"from": format_date(start_of_day(days[0])) if days else "", "to": format_date(start_of_day(days[-1])) if days else ""},
|
||||
|
||||
Reference in New Issue
Block a user