优化(直播履约): 即时选号并收敛订单快照同步
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""低频订单对账兜底;正常同步由 order_site 签名 Webhook 驱动。"""
|
||||
"""低频状态对账兜底;正常订单同步完全由 order_site 事务 Outbox 驱动。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -12,6 +12,7 @@ from ...database import SessionLocal
|
||||
_stop_event = threading.Event()
|
||||
_thread: threading.Thread | None = None
|
||||
_lock = threading.Lock()
|
||||
_LAST_TASK_ID = 0
|
||||
|
||||
|
||||
def _interval_seconds() -> int:
|
||||
@@ -23,6 +24,7 @@ def _interval_seconds() -> int:
|
||||
|
||||
|
||||
def _run() -> None:
|
||||
global _LAST_TASK_ID
|
||||
from . import service
|
||||
|
||||
while not _stop_event.is_set():
|
||||
@@ -31,11 +33,20 @@ def _run() -> None:
|
||||
break
|
||||
db = SessionLocal()
|
||||
try:
|
||||
result = service.sync_pending_tasks(db, limit=500)
|
||||
queued = service.reconcile_binding_state_outbox(db, limit=500)
|
||||
queued = 0
|
||||
for _page in range(20):
|
||||
result = service.reconcile_binding_state_outbox(
|
||||
db,
|
||||
limit=500,
|
||||
after_task_id=_LAST_TASK_ID,
|
||||
)
|
||||
queued += int(result["queued"])
|
||||
_LAST_TASK_ID = int(result["nextTaskId"])
|
||||
if not result["hasMore"]:
|
||||
_LAST_TASK_ID = 0
|
||||
break
|
||||
logger.info(
|
||||
"直播账号履约低频对账完成: order_sync={} outbox_requeued={}",
|
||||
result,
|
||||
"直播账号履约低频对账完成: outbox_requeued={}",
|
||||
queued,
|
||||
)
|
||||
except Exception as exc: # noqa: BLE001 - 对账失败等待下一轮
|
||||
|
||||
Reference in New Issue
Block a user