Skip to content

Commit

Permalink
fix(cli): Update progress bar on secondly interval (#6155)
Browse files Browse the repository at this point in the history
A small update to the CLI progress bar so that it doesn't (appear to) hang for long periods when it takes time for new resources to be found. This change updates the progress bar every second.

##  📹 Demo 

https://user-images.githubusercontent.com/1121616/210093868-d6881c2b-dca3-4046-8c2b-c8aa2fd50f66.mov
  • Loading branch information
hermanschaaf committed Jan 1, 2023
1 parent 48aafd0 commit 01a85b1
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions cli/cmd/sync2.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,40 @@ func syncConnectionV2(ctx context.Context, cqDir string, sourceClient *clients.S
}

g.Go(func() error {
for resource := range resources {
totalResources++
_ = bar.Add(1)
t := time.NewTicker(1 * time.Second)
defer func() {
for i := range destSubscriptions {
select {
case <-gctx.Done():
return gctx.Err()
case destSubscriptions[i] <- resource:
close(destSubscriptions[i])
}
t.Stop()
}()
for {
select {
case resource, ok := <-resources:
if !ok {
return nil
}
totalResources++
_ = bar.Add(1)
for i := range destSubscriptions {
select {
case <-gctx.Done():
return gctx.Err()
case destSubscriptions[i] <- resource:
}
}
case <-t.C:
_ = bar.Add(0)
case <-gctx.Done():
return nil
}
}
for i := range destSubscriptions {
close(destSubscriptions[i])
}
return nil
})

if err := g.Wait(); err != nil {
_ = bar.Finish()
return err
}

_ = bar.Finish()
syncTimeTook := time.Since(syncTime)

Expand Down

0 comments on commit 01a85b1

Please sign in to comment.