feat(fulfillment): 增加签名 Webhook 事务 Outbox

- 新增直播履约状态事务 Outbox 与签名投递 worker
- 增加 order_site 状态回传、重试和低频对账兜底
- 补充 Outbox、签名校验与集成接口测试
This commit is contained in:
yml
2026-11-18 10:59:20 +08:00
parent 00c4a268c2
commit bba3d9dac9
17 changed files with 967 additions and 114 deletions
+67
View File
@@ -1914,6 +1914,73 @@ class PlatformFulfillmentEvent(Base):
)
class IntegrationOutbox(Base):
"""跨系统待发送事件;与业务状态在同一数据库事务内提交。"""
__tablename__ = "integration_outbox"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
event_id: Mapped[str] = mapped_column(String(36), nullable=False, unique=True)
destination: Mapped[str] = mapped_column(
String(32), nullable=False, default="order_site", server_default="order_site"
)
event_type: Mapped[str] = mapped_column(String(128), nullable=False)
dedupe_key: Mapped[str | None] = mapped_column(
String(255), nullable=True, unique=True
)
payload_json: Mapped[dict] = mapped_column(JSON, nullable=False)
status: Mapped[str] = mapped_column(
String(16), nullable=False, default="pending", server_default="pending"
)
attempts: Mapped[int] = mapped_column(
Integer, nullable=False, default=0, server_default="0"
)
next_attempt_at: Mapped[datetime] = mapped_column(
UTCDateTime, nullable=False, default=_utcnow
)
locked_at: Mapped[datetime | None] = mapped_column(UTCDateTime, nullable=True)
sent_at: Mapped[datetime | None] = mapped_column(UTCDateTime, nullable=True)
last_error: Mapped[str] = mapped_column(
Text, nullable=False, default=""
)
created_at: Mapped[datetime] = mapped_column(
UTCDateTime, nullable=False, default=_utcnow
)
__table_args__ = (
Index(
"ix_integration_outbox_due",
"status",
"next_attempt_at",
"id",
),
Index(
"ix_integration_outbox_destination",
"destination",
"status",
"id",
),
)
class IntegrationInbox(Base):
"""入站 Webhook 幂等表,event_id 全局唯一。"""
__tablename__ = "integration_inbox"
event_id: Mapped[str] = mapped_column(String(36), primary_key=True)
source: Mapped[str] = mapped_column(
String(32), nullable=False, default="", server_default=""
)
event_type: Mapped[str] = mapped_column(
String(128), nullable=False, default="", server_default=""
)
received_at: Mapped[datetime] = mapped_column(
UTCDateTime, nullable=False, default=_utcnow
)
processed_at: Mapped[datetime | None] = mapped_column(UTCDateTime, nullable=True)
class AutomationJob(Base):
"""自动化作业定义。状态落库,进程重启不丢调度进度。"""