publishChatStreamNotify broadcasts a per-chat stream notification via PostgreSQL pubsub so that all replicas can merge durable database updates with transient control events.
(chatID uuid.UUID, notify coderdpubsub.ChatStreamNotifyMessage)
| 5487 | // PostgreSQL pubsub so that all replicas can merge durable database updates |
| 5488 | // with transient control events. |
| 5489 | func (p *Server) publishChatStreamNotify(chatID uuid.UUID, notify coderdpubsub.ChatStreamNotifyMessage) { |
| 5490 | if p.pubsub == nil { |
| 5491 | return |
| 5492 | } |
| 5493 | payload, err := json.Marshal(notify) |
| 5494 | if err != nil { |
| 5495 | p.logger.Error(context.Background(), "failed to marshal chat stream notify", |
| 5496 | slog.F("chat_id", chatID), |
| 5497 | slog.Error(err), |
| 5498 | ) |
| 5499 | return |
| 5500 | } |
| 5501 | if err := p.pubsub.Publish(coderdpubsub.ChatStreamNotifyChannel(chatID), payload); err != nil { |
| 5502 | p.logger.Error(context.Background(), "failed to publish chat stream notify", |
| 5503 | slog.F("chat_id", chatID), |
| 5504 | slog.Error(err), |
| 5505 | ) |
| 5506 | } |
| 5507 | } |
| 5508 | |
| 5509 | // publishChatPubsubEvents broadcasts a lifecycle event for each affected chat. |
| 5510 | func (p *Server) publishChatPubsubEvents(chats []database.Chat, kind codersdk.ChatWatchEventKind) { |