perf(fulfillment): 修复 Outbox 状态版本去重、跨进程实时推送与数据库默认配置
This commit is contained in:
@@ -9,7 +9,11 @@ from sqlalchemy.orm import Session
|
||||
from ...models import (
|
||||
PlatformFulfillmentTask,
|
||||
)
|
||||
from .order_site_notifier import enqueue_order_site_binding_state
|
||||
from .events import publish_after_commit
|
||||
from .order_site_notifier import (
|
||||
binding_state_hash,
|
||||
enqueue_order_site_binding_state,
|
||||
)
|
||||
from .views import customer_binding_out
|
||||
|
||||
|
||||
@@ -26,16 +30,26 @@ def _emit_order_site_binding_state(
|
||||
.with_for_update()
|
||||
.one()
|
||||
)
|
||||
next_state_version = int(task.state_version or 0) + 1
|
||||
payload = customer_binding_out(db, task_id)
|
||||
payload["stateVersion"] = next_state_version
|
||||
if extra:
|
||||
payload.update(extra)
|
||||
state_hash = binding_state_hash(payload)
|
||||
if not extra and (task.last_emitted_state_hash or "") == state_hash:
|
||||
return False
|
||||
|
||||
next_state_version = int(task.state_version or 0) + 1
|
||||
payload["stateVersion"] = next_state_version
|
||||
enqueued = enqueue_order_site_binding_state(
|
||||
db,
|
||||
payload,
|
||||
)
|
||||
if enqueued:
|
||||
task.state_version = next_state_version
|
||||
task.last_emitted_state_hash = state_hash
|
||||
db.flush()
|
||||
publish_after_commit(
|
||||
db,
|
||||
scope="tasks",
|
||||
action="binding_state_emitted",
|
||||
)
|
||||
return enqueued
|
||||
|
||||
Reference in New Issue
Block a user