Created
October 27, 2021 02:53
-
-
Save jayhuang75/5020c5d0c95fa2da3747541d13611ab2 to your computer and use it in GitHub Desktop.
go-train-delay-changes.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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