[push] migrate to Notify method where posible

This commit is contained in:
Aleksandr Soloshenko 2025-07-22 08:01:35 +07:00 committed by Aleksandr
parent 722272df6c
commit d86a0e4234
2 changed files with 7 additions and 12 deletions

View File

@ -220,18 +220,14 @@ func (s *Service) Enqueue(device models.Device, message MessageIn, opts EnqueueO
return state, err
}
if device.PushToken == nil {
return state, nil
}
go func(token string) {
if err := s.pushSvc.Enqueue(token, push.NewMessageEnqueuedEvent()); err != nil {
s.logger.Error("Can't enqueue message", zap.String("token", token), zap.Error(err))
}
}(*device.PushToken)
s.messagesCounter.WithLabelValues(string(state.State)).Inc()
go func(userID, deviceID string) {
if err := s.pushSvc.Notify(userID, &deviceID, push.NewMessageEnqueuedEvent()); err != nil {
s.logger.Error("can't notify device", zap.Error(err), zap.String("user_id", userID), zap.String("device_id", deviceID))
}
}(device.UserID, device.ID)
return state, nil
}
@ -242,7 +238,7 @@ func (s *Service) ExportInbox(device models.Device, since, until time.Time) erro
event := push.NewMessagesExportRequestedEvent(since, until)
return s.pushSvc.Enqueue(*device.PushToken, event)
return s.pushSvc.Notify(device.UserID, &device.ID, event)
}
func (s *Service) Clean(ctx context.Context) error {

View File

@ -158,7 +158,6 @@ func (s *Service) Notify(userID string, deviceID *string, event *domain.Event) e
devices, err := s.devicesSvc.Select(userID, filters...)
if err != nil {
s.logger.Error("Failed to select devices", append(logFields, zap.Error(err))...)
return fmt.Errorf("failed to select devices: %w", err)
}