uint/uint64全部改为uint32
This commit is contained in:
@@ -16,13 +16,13 @@ import (
|
||||
// Service 定义了通知领域的核心业务逻辑接口
|
||||
type Service interface {
|
||||
// SendBatchAlarm 向一批用户发送告警通知。它会并发地为每个用户执行带故障转移的发送逻辑。
|
||||
SendBatchAlarm(ctx context.Context, userIDs []uint, content notify.AlarmContent) error
|
||||
SendBatchAlarm(ctx context.Context, userIDs []uint32, content notify.AlarmContent) error
|
||||
|
||||
// BroadcastAlarm 向所有用户发送告警通知。它会并发地为每个用户执行带故障转移的发送逻辑。
|
||||
BroadcastAlarm(ctx context.Context, content notify.AlarmContent) error
|
||||
|
||||
// SendTestMessage 向指定用户发送一条测试消息,用于手动验证特定通知渠道的配置。
|
||||
SendTestMessage(ctx context.Context, userID uint, notifierType models.NotifierType) error
|
||||
SendTestMessage(ctx context.Context, userID uint32, notifierType models.NotifierType) error
|
||||
}
|
||||
|
||||
// failoverService 是 Service 接口的实现,提供了故障转移功能
|
||||
@@ -32,7 +32,7 @@ type failoverService struct {
|
||||
notifiers map[models.NotifierType]notify.Notifier
|
||||
primaryNotifier notify.Notifier
|
||||
failureThreshold int
|
||||
failureCounters *sync.Map // 使用 sync.Map 来安全地并发读写失败计数, key: userID (uint), value: counter (int)
|
||||
failureCounters *sync.Map // 使用 sync.Map 来安全地并发读写失败计数, key: userID (uint32), value: counter (int)
|
||||
notificationRepo repository.NotificationRepository
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func NewFailoverService(
|
||||
}
|
||||
|
||||
// SendBatchAlarm 实现了向多个用户并发发送告警的功能
|
||||
func (s *failoverService) SendBatchAlarm(ctx context.Context, userIDs []uint, content notify.AlarmContent) error {
|
||||
func (s *failoverService) SendBatchAlarm(ctx context.Context, userIDs []uint32, content notify.AlarmContent) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "SendBatchAlarm")
|
||||
var wg sync.WaitGroup
|
||||
var mu sync.Mutex
|
||||
@@ -77,7 +77,7 @@ func (s *failoverService) SendBatchAlarm(ctx context.Context, userIDs []uint, co
|
||||
|
||||
for _, userID := range userIDs {
|
||||
wg.Add(1)
|
||||
go func(id uint) {
|
||||
go func(id uint32) {
|
||||
defer wg.Done()
|
||||
if err := s.sendAlarmToUser(serviceCtx, id, content); err != nil {
|
||||
mu.Lock()
|
||||
@@ -108,7 +108,7 @@ func (s *failoverService) BroadcastAlarm(ctx context.Context, content notify.Ala
|
||||
return fmt.Errorf("广播告警失败:查找所有用户时出错: %w", err)
|
||||
}
|
||||
|
||||
var userIDs []uint
|
||||
var userIDs []uint32
|
||||
for _, user := range users {
|
||||
userIDs = append(userIDs, user.ID)
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func (s *failoverService) BroadcastAlarm(ctx context.Context, content notify.Ala
|
||||
}
|
||||
|
||||
// sendAlarmToUser 是为单个用户发送告警的内部方法,包含了完整的故障转移逻辑
|
||||
func (s *failoverService) sendAlarmToUser(ctx context.Context, userID uint, content notify.AlarmContent) error {
|
||||
func (s *failoverService) sendAlarmToUser(ctx context.Context, userID uint32, content notify.AlarmContent) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "sendAlarmToUser")
|
||||
user, err := s.userRepo.FindByID(serviceCtx, userID)
|
||||
if err != nil {
|
||||
@@ -187,7 +187,7 @@ func (s *failoverService) sendAlarmToUser(ctx context.Context, userID uint, cont
|
||||
}
|
||||
|
||||
// SendTestMessage 实现了手动发送测试消息的功能
|
||||
func (s *failoverService) SendTestMessage(ctx context.Context, userID uint, notifierType models.NotifierType) error {
|
||||
func (s *failoverService) SendTestMessage(ctx context.Context, userID uint32, notifierType models.NotifierType) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "SendTestMessage")
|
||||
user, err := s.userRepo.FindByID(serviceCtx, userID)
|
||||
if err != nil {
|
||||
@@ -261,7 +261,7 @@ func getAddressForNotifier(notifierType models.NotifierType, contact models.Cont
|
||||
// err: 如果发送失败,记录的错误信息
|
||||
func (s *failoverService) recordNotificationAttempt(
|
||||
ctx context.Context,
|
||||
userID uint,
|
||||
userID uint32,
|
||||
notifierType models.NotifierType,
|
||||
content notify.AlarmContent,
|
||||
toAddress string,
|
||||
|
||||
Reference in New Issue
Block a user