Skip to content

Commit

Permalink
fix: add unique event validation
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Jul 28, 2023
1 parent 16ba49e commit 8492c66
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package events
import (
"time"

"github.com/flanksource/commons/collections/set"
"github.com/flanksource/commons/logger"
"github.com/flanksource/incident-commander/api"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -59,7 +61,14 @@ func StartConsumers(gormDB *gorm.DB, config Config) {
allConsumers = append(allConsumers, NewUpstreamPushConsumer(gormDB, config))
}

uniqWatchEvents := set.New[string]()
for _, c := range allConsumers {
for _, we := range c.WatchEvents {
if uniqWatchEvents.Contains(we) {
logger.Fatalf("Error starting consumers: event[%s] has multiple consumers", we)
}
}
uniqWatchEvents.Add(c.WatchEvents...)
go c.Listen()
}
}
2 changes: 1 addition & 1 deletion events/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func NewNotificationConsumer(db *gorm.DB) EventConsumer {
return EventConsumer{
WatchEvents: []string{
EventNotificationSend, EventNotificationUpdate, EventNotificationDelete,
EventNotificationUpdate, EventNotificationDelete,
EventIncidentCreated,
EventIncidentResponderRemoved,
EventIncidentDODAdded, EventIncidentDODPassed, EventIncidentDODRegressed,
Expand Down

0 comments on commit 8492c66

Please sign in to comment.