refactor: complete durable transfer execution settlement

This commit is contained in:
jxxghp
2026-08-27 20:27:42 +08:00
parent 8e7a553c1e
commit e82ce8447c
69 changed files with 11948 additions and 275 deletions
+14 -10
View File
@@ -167,16 +167,18 @@ class DurableEventCommand:
def execute(
self,
*,
intent: OutboxIntent | Callable[[T], OutboxIntent],
intent: OutboxIntent | Callable[[T], OutboxIntent] | None,
stage_business: Callable[[], T],
publish: Callable[[], None],
publish: Callable[[], None] | None,
after_commit: Callable[[], None] | None = None,
) -> T:
"""原子提交业务与 intent,再保持原顺序执行提交后动作和即时广播。"""
"""原子提交业务与可选 intent,再执行可选提交后动作和广播。"""
resolved_intent: OutboxIntent | None = None
try:
result = stage_business()
resolved_intent = intent(result) if callable(intent) else intent
self._outbox.stage(resolved_intent, datetime.now(timezone.utc))
if intent is not None:
resolved_intent = intent(result) if callable(intent) else intent
self._outbox.stage(resolved_intent, datetime.now(timezone.utc))
self._unit_of_work.commit()
except Exception:
self._unit_of_work.rollback()
@@ -184,11 +186,13 @@ class DurableEventCommand:
if after_commit:
after_commit()
publish()
self._outbox.complete_by_event_key(
resolved_intent.event_key,
datetime.now(timezone.utc),
)
if publish:
publish()
if resolved_intent is not None and publish is not None:
self._outbox.complete_by_event_key(
resolved_intent.event_key,
datetime.now(timezone.utc),
)
return result