Skip to content

Commit

Permalink
chore: rename events/consumers.go -> events/event_consumer.go
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Jul 25, 2023
1 parent 6f1cf3c commit 6045e54
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
20 changes: 2 additions & 18 deletions events/consumers.go → events/event_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,14 @@ func (e *EventConsumer) listenToPostgresNotify(pgNotify chan bool) {
if err != nil {
return fmt.Errorf("error listening to database notifications: %v", err)
}
logger.Infof("listening to database notifications")
logger.Debugf("listening to database notifications")

for {
notification, err := conn.Conn().WaitForNotification(ctx)
_, err := conn.Conn().WaitForNotification(ctx)
if err != nil {
return fmt.Errorf("error listening to database notifications: %v", err)
}

logger.Tracef("Received database notification: %+v", notification)
pgNotify <- true
}
}
Expand Down Expand Up @@ -182,18 +181,3 @@ func (e *EventConsumer) Listen() {
}
}
}

func StartConsumers(gormDB *gorm.DB, config Config) {
allConsumers := []EventConsumer{
NewTeamConsumer(gormDB),
NewNotificationConsumer(gormDB),
NewResponderConsumer(gormDB),
}
if config.UpstreamPush.Valid() {
allConsumers = append(allConsumers, NewUpstreamPushConsumer(gormDB, config))
}

for _, c := range allConsumers {
go c.Listen()
}
}
16 changes: 16 additions & 0 deletions events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

"github.com/flanksource/incident-commander/api"
"gorm.io/gorm"
)

const (
Expand Down Expand Up @@ -46,3 +47,18 @@ const (
type Config struct {
UpstreamPush api.UpstreamConfig
}

func StartConsumers(gormDB *gorm.DB, config Config) {
allConsumers := []EventConsumer{
NewTeamConsumer(gormDB),
NewNotificationConsumer(gormDB),
NewResponderConsumer(gormDB),
}
if config.UpstreamPush.Valid() {
allConsumers = append(allConsumers, NewUpstreamPushConsumer(gormDB, config))
}

for _, c := range allConsumers {
go c.Listen()
}
}

0 comments on commit 6045e54

Please sign in to comment.