Do multiple org-hour records in parallel

This commit is contained in:
Bryan Boreham
2019-06-08 13:50:03 +00:00
parent dd71191bb6
commit f9f28f6d78

View File

@@ -158,17 +158,31 @@ func main() {
totals := newSummary()
if recordsFile != "" {
f, err := os.Open(recordsFile)
checkFatal(err)
defer f.Close()
records := bufio.NewScanner(f)
for records.Scan() {
scanner.HandleRecord(context.Background(), orgs, records.Text())
}
checkFatal(records.Err())
f, err := os.Open(recordsFile)
checkFatal(err)
defer f.Close()
// Create multiple goroutines reading off one queue of records to delete
queue := make(chan string)
var wait sync.WaitGroup
wait.Add(scanner.segments)
for i := 0; i < scanner.segments; i++ {
go func() {
for record := range queue {
scanner.HandleRecord(context.Background(), orgs, record)
}
wait.Done()
}()
}
records := bufio.NewScanner(f)
for records.Scan() {
queue <- records.Text()
}
checkFatal(records.Err())
close(queue)
wait.Wait()
fmt.Printf("\n")
totals.print()
}