vmctl: fix progress bar not being stopped on error during import process (#3023)

vmctl: fix progress bar not being stopped on error during import process
This commit is contained in:
Zakhar Bessarab 2022-08-26 20:20:27 +04:00 committed by GitHub
parent f49c9bb700
commit 30fb4b948e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 3 deletions

View file

@ -52,6 +52,7 @@ func (ip *influxProcessor) run(silent, verbose bool) error {
if err := barpool.Start(); err != nil {
return err
}
defer barpool.Stop()
seriesCh := make(chan *influx.Series)
errCh := make(chan error)
@ -96,7 +97,7 @@ func (ip *influxProcessor) run(silent, verbose bool) error {
for err := range errCh {
return fmt.Errorf("import process failed: %s", err)
}
barpool.Stop()
log.Println("Import finished!")
log.Print(ip.im.Stats())
return nil

View file

@ -82,6 +82,9 @@ func (op *otsdbProcessor) run(silent, verbose bool) error {
errCh := make(chan error)
// we're going to make serieslist * queryRanges queries, so we should represent that in the progress bar
bar := pb.StartNew(len(serieslist) * queryRanges)
defer func(bar *pb.ProgressBar) {
bar.Finish()
}(bar)
var wg sync.WaitGroup
wg.Add(op.otsdbcc)
for i := 0; i < op.otsdbcc; i++ {

View file

@ -43,6 +43,7 @@ func (pp *prometheusProcessor) run(silent, verbose bool) error {
if err := barpool.Start(); err != nil {
return err
}
defer barpool.Stop()
blockReadersCh := make(chan tsdb.BlockReader)
errCh := make(chan error, pp.cc)
@ -89,7 +90,7 @@ func (pp *prometheusProcessor) run(silent, verbose bool) error {
for err := range errCh {
return fmt.Errorf("import process failed: %s", err)
}
barpool.Stop()
log.Println("Import finished!")
log.Print(pp.im.Stats())
return nil

View file

@ -89,6 +89,7 @@ func (p *vmNativeProcessor) run(ctx context.Context) error {
log.Printf("error start process bars pool: %s", err)
return err
}
defer barpool.Stop()
w := io.Writer(pw)
if p.rateLimit > 0 {
@ -106,7 +107,6 @@ func (p *vmNativeProcessor) run(ctx context.Context) error {
}
<-sync
barpool.Stop()
log.Println("Import finished!")
return nil
}