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:
77
backend/cmd/notification/main.go
Normal file
77
backend/cmd/notification/main.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/LoveLosita/smartflow/backend/bootstrap"
|
||||
kafkabus "github.com/LoveLosita/smartflow/backend/infra/kafka"
|
||||
outboxinfra "github.com/LoveLosita/smartflow/backend/infra/outbox"
|
||||
notificationdao "github.com/LoveLosita/smartflow/backend/services/notification/dao"
|
||||
notificationrpc "github.com/LoveLosita/smartflow/backend/services/notification/rpc"
|
||||
notificationsv "github.com/LoveLosita/smartflow/backend/services/notification/sv"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := bootstrap.LoadConfig(); err != nil {
|
||||
log.Fatalf("failed to load config: %v", err)
|
||||
}
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
db, err := notificationdao.OpenDBFromConfig()
|
||||
if err != nil {
|
||||
log.Fatalf("failed to connect notification database: %v", err)
|
||||
}
|
||||
|
||||
channelDAO := notificationdao.NewChannelDAO(db)
|
||||
recordDAO := notificationdao.NewRecordDAO(db)
|
||||
svc, err := notificationsv.NewNotificationServiceWithFeishuWebhook(recordDAO, channelDAO, notificationsv.FeishuWebhookProviderOptions{
|
||||
FrontendBaseURL: viper.GetString("notification.frontendBaseURL"),
|
||||
}, notificationsv.ServiceOptions{})
|
||||
if err != nil {
|
||||
log.Fatalf("failed to initialize notification service: %v", err)
|
||||
}
|
||||
|
||||
outboxRepo := outboxinfra.NewRepository(db)
|
||||
eventBus, err := outboxinfra.NewEventBus(outboxRepo, kafkabus.LoadConfig())
|
||||
if err != nil {
|
||||
log.Fatalf("failed to initialize notification outbox bus: %v", err)
|
||||
}
|
||||
if eventBus != nil {
|
||||
if err := notificationsv.RegisterFeishuRequestedHandler(eventBus, outboxRepo, svc); err != nil {
|
||||
log.Fatalf("failed to register notification outbox handler: %v", err)
|
||||
}
|
||||
eventBus.Start(ctx)
|
||||
defer eventBus.Close()
|
||||
log.Println("Notification outbox consumer started")
|
||||
} else {
|
||||
log.Println("Notification outbox consumer is disabled")
|
||||
}
|
||||
|
||||
svc.StartRetryLoop(ctx, viper.GetDuration("notification.retryScanEvery"), viper.GetInt("notification.retryBatchSize"))
|
||||
log.Println("Notification retry scanner started")
|
||||
|
||||
server, listenOn, err := notificationrpc.NewServer(notificationrpc.ServerOptions{
|
||||
ListenOn: viper.GetString("notification.rpc.listenOn"),
|
||||
Timeout: viper.GetDuration("notification.rpc.timeout"),
|
||||
Service: svc,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("failed to build notification zrpc server: %v", err)
|
||||
}
|
||||
defer server.Stop()
|
||||
|
||||
go func() {
|
||||
log.Printf("notification zrpc service starting on %s", listenOn)
|
||||
server.Start()
|
||||
}()
|
||||
|
||||
<-ctx.Done()
|
||||
log.Println("notification service stopping")
|
||||
}
|
||||
Reference in New Issue
Block a user