perf(fulfillment): 修复 Outbox 状态版本去重、跨进程实时推送与数据库默认配置
This commit is contained in:
@@ -60,6 +60,7 @@ from .binding_status import (
|
||||
_customer_task_message,
|
||||
)
|
||||
from .common import FLOW_VERSION_CLEAN, SCOPE_ELITE, _has_game_home_profile, _now
|
||||
from .order_site_notifier import binding_state_hash
|
||||
from .outbox import _emit_order_site_binding_state
|
||||
from .repository import (
|
||||
_binding_qr_expired,
|
||||
@@ -2070,28 +2071,44 @@ def reconcile_binding_state_outbox(
|
||||
limit: int = 500,
|
||||
after_task_id: int = 0,
|
||||
) -> dict[str, Any]:
|
||||
"""按 ID 游标补齐 active 快照;批次只限制吞吐,不形成永久扫描窗口。"""
|
||||
"""只读筛查漂移的 clean_v1 活跃任务再按需加锁写 Outbox;历史冻结单不参与。"""
|
||||
from .views import customer_binding_out
|
||||
|
||||
batch_size = max(1, min(limit, 500))
|
||||
normalized_after = max(0, int(after_task_id or 0))
|
||||
task_ids = [
|
||||
int(row.id)
|
||||
for row in (
|
||||
db.query(PlatformFulfillmentTask.id)
|
||||
.filter(
|
||||
PlatformFulfillmentTask.id > normalized_after,
|
||||
PlatformFulfillmentTask.execution_status.notin_(
|
||||
["completed", "cancelled"]
|
||||
),
|
||||
)
|
||||
.order_by(PlatformFulfillmentTask.id.asc())
|
||||
.limit(batch_size)
|
||||
.all()
|
||||
candidates = (
|
||||
db.query(
|
||||
PlatformFulfillmentTask.id,
|
||||
PlatformFulfillmentTask.last_emitted_state_hash,
|
||||
)
|
||||
]
|
||||
queued = sum(
|
||||
1 for task_id in task_ids if _emit_order_site_binding_state(db, task_id)
|
||||
.filter(
|
||||
PlatformFulfillmentTask.id > normalized_after,
|
||||
PlatformFulfillmentTask.flow_version == FLOW_VERSION_CLEAN,
|
||||
PlatformFulfillmentTask.execution_status.notin_(
|
||||
["completed", "cancelled"]
|
||||
),
|
||||
)
|
||||
.order_by(PlatformFulfillmentTask.id.asc())
|
||||
.limit(batch_size)
|
||||
.all()
|
||||
)
|
||||
db.commit()
|
||||
task_ids = [int(row.id) for row in candidates]
|
||||
drifted_ids: list[int] = []
|
||||
for row in candidates:
|
||||
task_id = int(row.id)
|
||||
last_hash = str(row.last_emitted_state_hash or "")
|
||||
if not last_hash:
|
||||
drifted_ids.append(task_id)
|
||||
continue
|
||||
payload = customer_binding_out(db, task_id)
|
||||
if binding_state_hash(payload) != last_hash:
|
||||
drifted_ids.append(task_id)
|
||||
|
||||
queued = sum(
|
||||
1 for task_id in drifted_ids if _emit_order_site_binding_state(db, task_id)
|
||||
)
|
||||
if queued:
|
||||
db.commit()
|
||||
return {
|
||||
"queued": queued,
|
||||
"nextTaskId": max(task_ids, default=normalized_after),
|
||||
|
||||
Reference in New Issue
Block a user