(ctx context.Context)
| 52 | } |
| 53 | |
| 54 | func (s *Server) processNotificationEvents(ctx context.Context) error { |
| 55 | res, err := s.client.ListNotificationEvents(ctx, &pb.ListNotificationEventsReq{}) |
| 56 | if err != nil { |
| 57 | return err |
| 58 | } |
| 59 | |
| 60 | var wg sync.WaitGroup |
| 61 | sem := semaphore.NewWeighted(10) |
| 62 | for _, ev := range res.Events { |
| 63 | wg.Add(1) |
| 64 | if err := sem.Acquire(ctx, 1); err != nil { |
| 65 | return err |
| 66 | } |
| 67 | |
| 68 | go func(ev *pb.NotificationEvent) { |
| 69 | defer sem.Release(1) |
| 70 | defer wg.Done() |
| 71 | err := s.sendNotification(ctx, ev) |
| 72 | err = s.updateNotificationEvent(ctx, ev, err) |
| 73 | if err != nil { |
| 74 | fmt.Printf("processing event: %v\n", err) |
| 75 | } |
| 76 | }(ev) |
| 77 | } |
| 78 | |
| 79 | go func() { |
| 80 | wg.Wait() |
| 81 | }() |
| 82 | |
| 83 | return nil |
| 84 | } |
| 85 | |
| 86 | func (s *Server) sendNotification(ctx context.Context, ev *pb.NotificationEvent) error { |
| 87 | m := gomail.NewMessage() |
no test coverage detected