feat(feishu): 添加飞书入站事件inbox和混合数据库协调功能

- 实现飞书入站事件持久化inbox机制,支持状态管理、租约锁定和重试退避
- 添加混合数据库基线协调工具,确保平台PostgreSQL结构安全对齐
- 增加运行组件心跳检测和readiness就绪检查机制
- 实现app_ticket事件的安全轮换和验证处理
- 添加生产环境运行编排和fail-closed安全机制
- 支持webhook快速确认和长连接独立进程处理
- 完善个人数据擦除时的待处理事件清理功能
```
This commit is contained in:
2026-07-27 17:14:37 +08:00
parent d7db84571d
commit eb8267ed18
61 changed files with 8703 additions and 183 deletions

View File

@@ -16,7 +16,12 @@ from app.modules.feishu_users.constants import (
FeishuUserStatus,
parse_admin_identities,
)
from app.modules.feishu.services import (
FeishuInboundService,
current_inbound_event_key,
)
from app.modules.feishu_users.bootstrap import admin_bootstrap_identity_hash
from app.modules.feishu_users.identifiers import feishu_audit_identity_hash
from app.modules.feishu_users.models import (
FeishuAdminBootstrapTombstone,
FeishuUser,
@@ -187,6 +192,10 @@ class FeishuPersonalDataService:
user.open_id,
user.union_id,
user.user_id,
feishu_audit_identity_hash(
user.tenant_key,
user.open_id,
),
)
if value
},
@@ -230,6 +239,21 @@ class FeishuPersonalDataService:
"subscriptions": subscriptions,
}
def clear_pending_inbound_events(
db: Session,
_owner_id: int,
_anonymous_id: str,
) -> dict[str, int]:
# The caller already holds the FeishuUser row. Inbound handlers
# acquire that same identity fence before their own receipt row, so
# erasure can safely fence related receipts in identity -> inbox order.
cleared = FeishuInboundService(db).erase_identity_payloads(
tenant_key=user.tenant_key,
open_id=user.open_id,
exclude_event_key=current_inbound_event_key(),
)
return {"inbound_events": cleared}
def finalize_identity(
db: Session,
_owner_id: int,
@@ -281,7 +305,7 @@ class FeishuPersonalDataService:
return self.erasure.confirm_and_erase(
user.id,
confirmation_code,
before_hooks=(delete_subscriptions,),
before_hooks=(delete_subscriptions, clear_pending_inbound_events),
extra_hooks=(*self.extra_hooks, finalize_identity),
)