Main runs the topology corresponding to the provided configuration. Depending on the input, it either blocks forever (daemon) or terminates when all the records have been processed (batch).
(cfg *Config)
| 25 | // Depending on the input, it either blocks forever (daemon) or terminates when |
| 26 | // all the records have been processed (batch). |
| 27 | func Main(cfg *Config) error { |
| 28 | topology, err := NewTopologyFromConfig(cfg) |
| 29 | if err != nil { |
| 30 | return fmt.Errorf("can't create topology: %s", err) |
| 31 | } |
| 32 | |
| 33 | // Start the topology |
| 34 | topology.Start() |
| 35 | |
| 36 | // Now setup the wait condition for exiting the process in case the topology |
| 37 | // ends by itself. |
| 38 | topdone := make(chan bool) |
| 39 | go func() { |
| 40 | topology.Wait() |
| 41 | topdone <- true |
| 42 | }() |
| 43 | |
| 44 | // Begin dump statistics |
| 45 | stats := NewStatsDumper(topology) |
| 46 | stopStats := stats.Run() |
| 47 | |
| 48 | // Block until topology termination. |
| 49 | <-topdone |
| 50 | |
| 51 | // Stop the stats dumping goroutine (this also prints stats one last time). |
| 52 | stopStats() |
| 53 | |
| 54 | if err := topology.Metrics.Close(); err != nil { |
| 55 | logrus.WithError(err).Warnf("error closing metrics client") |
| 56 | } |
| 57 | |
| 58 | return topology.Error() |
| 59 | } |
no test coverage detected