Skip to content

Commit

Permalink
fix: remove loop variable reference bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Aug 5, 2023
1 parent 151b0de commit 3442567
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion events/event_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
type EventConsumer struct {
WatchEvents []string
// We process mutliple events and return the failed events
ProcessBatchFunc func(*api.Context, []api.Event) []*api.Event
ProcessBatchFunc func(*api.Context, []api.Event) []api.Event
BatchSize int
Consumers int
DB *gorm.DB
Expand Down
6 changes: 3 additions & 3 deletions events/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func NewNotificationSendConsumer(db *gorm.DB) EventConsumer {
}
}

func processNotificationEvents(ctx *api.Context, events []api.Event) []*api.Event {
var failedEvents []*api.Event
func processNotificationEvents(ctx *api.Context, events []api.Event) []api.Event {
var failedEvents []api.Event
for _, e := range events {
if err := handleNotificationEvent(ctx, e); err != nil {
e.Error = err.Error()
failedEvents = append(failedEvents, &e)
failedEvents = append(failedEvents, e)
}
}
return failedEvents
Expand Down
6 changes: 3 additions & 3 deletions events/responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ func NewResponderConsumer(db *gorm.DB) EventConsumer {
}
}

func processResponderEvents(ctx *api.Context, events []api.Event) []*api.Event {
var failedEvents []*api.Event
func processResponderEvents(ctx *api.Context, events []api.Event) []api.Event {
var failedEvents []api.Event
for _, e := range events {
if err := handleResponderEvent(ctx, e); err != nil {
e.Error = err.Error()
failedEvents = append(failedEvents, &e)
failedEvents = append(failedEvents, e)
}
}
return failedEvents
Expand Down
6 changes: 3 additions & 3 deletions events/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ func NewTeamConsumer(db *gorm.DB) EventConsumer {
}
}

func processTeamEvents(ctx *api.Context, events []api.Event) []*api.Event {
var failedEvents []*api.Event
func processTeamEvents(ctx *api.Context, events []api.Event) []api.Event {
var failedEvents []api.Event
for _, e := range events {
if err := handleTeamEvent(ctx, e); err != nil {
e.Error = err.Error()
failedEvents = append(failedEvents, &e)
failedEvents = append(failedEvents, e)
}
}
return failedEvents
Expand Down
16 changes: 8 additions & 8 deletions events/upstream_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ func NewUpstreamPushConsumer(db *gorm.DB, config Config) EventConsumer {
}
}

func handleUpstreamPushEvents(ctx *api.Context, events []api.Event) []*api.Event {
func handleUpstreamPushEvents(ctx *api.Context, events []api.Event) []api.Event {
if upstreamPushEventHandler == nil {
logger.Fatalf("Got push events but host is not configured")
}

var failedEvents []*api.Event
var failedEvents []api.Event
var eventsToProcess []api.Event
for _, e := range events {
if e.Name != EventPushQueueCreate {
e.Error = fmt.Errorf("Unrecognized event name: %s", e.Name).Error()
failedEvents = append(failedEvents, &e)
failedEvents = append(failedEvents, e)
} else {
eventsToProcess = append(eventsToProcess, e)
}
Expand All @@ -55,24 +55,24 @@ func newPushToUpstreamEventHandler(conf upstream.UpstreamConfig) *pushToUpstream
}
}

func addErrorToFailedEvents(events []api.Event, err error) []*api.Event {
var failedEvents []*api.Event
func addErrorToFailedEvents(events []api.Event, err error) []api.Event {
var failedEvents []api.Event
for _, e := range events {
e.Error = err.Error()
failedEvents = append(failedEvents, &e)
failedEvents = append(failedEvents, e)
}
return failedEvents
}

// Run pushes data from decentralized instances to central incident commander
func (t *pushToUpstreamEventHandler) Run(ctx *api.Context, events []api.Event) []*api.Event {
func (t *pushToUpstreamEventHandler) Run(ctx *api.Context, events []api.Event) []api.Event {
upstreamMsg := &upstream.PushData{
AgentName: t.conf.AgentName,
}

gormDB := ctx.DB()

var failedEvents []*api.Event
var failedEvents []api.Event
for _, cl := range GroupChangelogsByTables(events) {
switch cl.tableName {
case "topologies":
Expand Down

0 comments on commit 3442567

Please sign in to comment.