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

@@ -0,0 +1,62 @@
package notification
import "time"
// SaveFeishuWebhookRequest 是 gateway 写入飞书 Webhook 通道配置的跨进程契约。
//
// 职责边界:
// 1. 只承载用户提交的配置字段,不做 URL、鉴权类型或 token 的业务校验;
// 2. user_id 由 gateway 从 JWT 上下文取得,不能信任前端传入;
// 3. bearer_token 只在服务内持久化和投递时使用,响应契约只返回 has_bearer_token。
type SaveFeishuWebhookRequest struct {
UserID int `json:"user_id"`
Enabled bool `json:"enabled"`
WebhookURL string `json:"webhook_url"`
AuthType string `json:"auth_type"`
BearerToken string `json:"bearer_token"`
}
// GetFeishuWebhookRequest 是查询飞书 Webhook 通道配置的跨进程契约。
type GetFeishuWebhookRequest struct {
UserID int `json:"user_id"`
}
// DeleteFeishuWebhookRequest 是删除飞书 Webhook 通道配置的跨进程契约。
type DeleteFeishuWebhookRequest struct {
UserID int `json:"user_id"`
}
// TestFeishuWebhookRequest 是触发飞书 Webhook 测试消息的跨进程契约。
type TestFeishuWebhookRequest struct {
UserID int `json:"user_id"`
}
// ChannelResponse 是通知通道配置返回给前端的脱敏视图。
//
// 职责边界:
// 1. 不返回 webhook_url 原文和 bearer_token 原文;
// 2. 只返回用户界面需要展示的开关、脱敏地址、鉴权类型和最近测试结果;
// 3. 不暴露 notification_records 的投递状态,二者属于不同读模型。
type ChannelResponse struct {
Channel string `json:"channel"`
Enabled bool `json:"enabled"`
Configured bool `json:"configured"`
WebhookURLMask string `json:"webhook_url_mask,omitempty"`
AuthType string `json:"auth_type"`
HasBearerToken bool `json:"has_bearer_token"`
LastTestStatus string `json:"last_test_status,omitempty"`
LastTestError string `json:"last_test_error,omitempty"`
LastTestAt *time.Time `json:"last_test_at,omitempty"`
}
// TestResult 描述一次飞书 Webhook 测试投递结果。
type TestResult struct {
Channel ChannelResponse `json:"channel"`
Status string `json:"status"`
Outcome string `json:"outcome"`
Message string `json:"message,omitempty"`
TraceID string `json:"trace_id,omitempty"`
SentAt time.Time `json:"sent_at"`
Skipped bool `json:"skipped"`
Provider string `json:"provider"`
}

View File

@@ -10,6 +10,8 @@ import (
const (
NotificationFeishuRequestedEventType = "notification.feishu.requested"
NotificationFeishuRequestedEventVersion = "1"
// DefaultFeishuNotificationDedupeWindow 是 notification 第一版固定的 30 分钟去重窗口。
DefaultFeishuNotificationDedupeWindow = 30 * time.Minute
)
// FeishuNotificationRequestedPayload 是飞书通知请求事件载荷。
@@ -80,3 +82,20 @@ func (p FeishuNotificationRequestedPayload) MessageKey() string {
func (p FeishuNotificationRequestedPayload) AggregateID() string {
return strings.TrimSpace(p.PreviewID)
}
// BuildFeishuNotificationDedupeKey 构造“user_id + trigger_type + time_window”去重键。
//
// 职责边界:
// 1. 供事件发布方在生成 `notification.feishu.requested` payload 时复用;
// 2. 只负责把固定窗口归一成稳定 key不负责落 notification_records
// 3. requestedAt 为空或非法时直接返回空字符串,让上游显式感知入参不完整。
func BuildFeishuNotificationDedupeKey(userID int, triggerType string, requestedAt time.Time, window time.Duration) string {
if window <= 0 {
window = DefaultFeishuNotificationDedupeWindow
}
if userID <= 0 || strings.TrimSpace(triggerType) == "" || requestedAt.IsZero() {
return ""
}
windowStart := requestedAt.Truncate(window)
return strconv.Itoa(userID) + ":" + strings.TrimSpace(triggerType) + ":" + windowStart.Format(time.RFC3339)
}

View File

@@ -0,0 +1,20 @@
package ports
import (
"context"
contracts "github.com/LoveLosita/smartflow/backend/shared/contracts/notification"
)
// NotificationCommandClient 是 gateway 调用 notification 服务的通道配置能力集合。
//
// 职责边界:
// 1. 只描述 HTTP 入口需要的配置查询、保存、删除和测试能力;
// 2. 不暴露 notification_records、provider、outbox consumer 或 retry loop 细节;
// 3. 具体通信协议由 gateway adapter 决定API 层保持 res, err 的统一调用语义。
type NotificationCommandClient interface {
GetFeishuWebhook(ctx context.Context, req contracts.GetFeishuWebhookRequest) (*contracts.ChannelResponse, error)
SaveFeishuWebhook(ctx context.Context, req contracts.SaveFeishuWebhookRequest) (*contracts.ChannelResponse, error)
DeleteFeishuWebhook(ctx context.Context, req contracts.DeleteFeishuWebhookRequest) error
TestFeishuWebhook(ctx context.Context, req contracts.TestFeishuWebhookRequest) (*contracts.TestResult, error)
}