filter ss events by account

This commit is contained in:
2026-01-20 21:11:02 -07:00
parent 1130366bf5
commit 4f2ae26d58
3 changed files with 42 additions and 20 deletions
+8 -1
View File
@@ -2,6 +2,7 @@ package middleware
import (
"context"
"fmt"
"path"
"ruben/inventory2/internal/logging"
"ruben/inventory2/internal/server/sse"
@@ -40,6 +41,7 @@ func (p *UpdateNotificationPublisher) Group(pathPattern string) *UpdateNotificat
return &p2
}
// Publish must be applied AFTER a middleware puts in the Identity into the gin.Context.
func (p *UpdateNotificationPublisher) Publish(pathPattern string) gin.HandlerFunc {
trimBasePathSegs := getPathSegments(p.trimBasePath)
trimmedBasePathPattern := path.Join(p.basePathPattern, pathPattern)
@@ -85,12 +87,17 @@ func (p *UpdateNotificationPublisher) Publish(pathPattern string) gin.HandlerFun
parentEvent = e
}
acctID := GetIdentity(c).Account.AccountID
for _, e := range events {
go func() {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
if err := p.sse.Send(ctx, e, nil); err != nil {
if err := p.sse.Send(ctx, sse.Event{
AccountID: acctID,
Type: e,
Data: []byte(fmt.Sprintf(`{"eventType": %q}`, e)),
}); err != nil {
p.log.Errorf("failed to send sse event to listener: %v", err)
}
}()