Version: 0.9.68.dev.260504

后端:
1. 阶段 3 notification 服务边界落地,新增 `cmd/notification`、`services/notification`、`gateway/notification`、`shared/contracts/notification` 和 notification port,按 userauth 同款最小手搓 zrpc 样板收口
2. notification outbox consumer、relay 和 retry loop 迁入独立服务入口,处理 `notification.feishu.requested`,gateway 改为通过 zrpc client 调用 notification
3. 清退旧单体 notification DAO/model/service/provider/runner 和 `service/events/notification_feishu.go`,旧实现不再作为活跃编译路径
4. 修复 outbox 路由归属、dispatch 启动扫描、Kafka topic 探测/投递超时、sending 租约恢复、毒消息 MarkDead 错误回传和 RPC timeout 边界
5. 同步调整 active-scheduler 触发通知事件、核心 outbox handler、MySQL 迁移边界和 notification 配置

文档:
1. 更新微服务迁移计划,将阶段 3 notification 标记为已完成,并明确下一阶段从 active-scheduler 开始
This commit is contained in:
Losita
2026-05-04 18:40:39 +08:00
parent 9742dc8b1c
commit abe3b4960e
41 changed files with 2178 additions and 889 deletions

View File

@@ -13,8 +13,6 @@ import (
sharedevents "github.com/LoveLosita/smartflow/backend/shared/events"
)
const requestedNotificationDedupeWindow = 30 * time.Minute
// EnqueueActiveScheduleTriggeredInTx 在事务内写入 active_schedule.triggered outbox 消息。
//
// 职责边界:
@@ -53,6 +51,9 @@ func EnqueueNotificationFeishuRequestedInTx(
maxRetry int,
payload sharedevents.FeishuNotificationRequestedPayload,
) error {
if err := ensureNotificationFeishuOutboxRoute(); err != nil {
return err
}
return enqueueContractEventInTx(
ctx,
outboxRepo,
@@ -73,6 +74,16 @@ func EnqueueNotificationFeishuRequestedInTx(
// 1. 只做 model -> contract DTO 映射;
// 2. 不校验 trigger 是否应该被处理,业务真值判断由 scanner / worker 完成;
// 3. 若 payload_json 不是合法 JSON返回 error让调用方回滚本次触发。
// ensureNotificationFeishuOutboxRoute 确保 publisher 侧能把飞书通知事件写入 notification outbox。
//
// 职责边界:
// 1. 这里只登记 event_type -> notification 服务归属,不注册 handler也不启动单体旧消费者
// 2. RegisterEventService 本身幂等,重复调用用于覆盖 API/worker 不同启动路径;
// 3. 若路由登记失败,直接返回给事务调用方,让 trigger 与 notification 入队一起回滚。
func ensureNotificationFeishuOutboxRoute() error {
return outboxinfra.RegisterEventService(sharedevents.NotificationFeishuRequestedEventType, outboxinfra.ServiceNotification)
}
func BuildTriggeredPayloadFromModel(row model.ActiveScheduleTrigger) (sharedevents.ActiveScheduleTriggeredPayload, error) {
var rawPayload json.RawMessage
if row.PayloadJSON != nil && strings.TrimSpace(*row.PayloadJSON) != "" {
@@ -144,12 +155,7 @@ func BuildNotificationDedupeKey(userID int, triggerType string, requestedAt time
if requestedAt.IsZero() {
requestedAt = time.Now()
}
windowStart := requestedAt.Truncate(requestedNotificationDedupeWindow)
return fmt.Sprintf("%d:%s:%s",
userID,
strings.TrimSpace(triggerType),
windowStart.Format(time.RFC3339),
)
return sharedevents.BuildFeishuNotificationDedupeKey(userID, triggerType, requestedAt, sharedevents.DefaultFeishuNotificationDedupeWindow)
}
func enqueueContractEventInTx(