Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Created October 27, 2021 02:53
Show Gist options
  • Select an option

  • Save jayhuang75/5020c5d0c95fa2da3747541d13611ab2 to your computer and use it in GitHub Desktop.

Select an option

Save jayhuang75/5020c5d0c95fa2da3747541d13611ab2 to your computer and use it in GitHub Desktop.
go-train-delay-changes.go
// Create a channel to handle messages to as they come in.
cm := make(chan *pubsub.Message)
defer close(cm)
// Handle individual messages in a goroutine.
go func(cm <-chan *pubsub.Message) {
for msg := range cm {
log.Debugf("[main] Got message :%q\n", string(msg.Data))
data, err := newProcessor.Run(1)
if err != nil {
log.Fatalf("[main] processing new coming message failed: %s", err)
}
if len(data) != 0 {
// insert data to db for initial load
log.Infof("[main] inserting %d records\n", len(data))
newDB.Insert(data)
} else {
log.Infof("[main] new coming email is not the Go Train Delay Alert \n")
}
msg.Ack()
}
}(cm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment