Skip to content

Commit

Permalink
progress: minor correctness fixes (#10871)
Browse files Browse the repository at this point in the history
* When waiting for dependencies, `select` on the context as well
  as the ticker
* Write multiple progress events "transactionally" (i.e. hold the
  lock for the duration to avoid other events being interleaved)
* Do not change "finished" steps back to "in progress" to prevent
  flickering

Signed-off-by: Milas Bowman <[email protected]>
  • Loading branch information
milas authored Aug 3, 2023
1 parent d7b1972 commit 80856ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pkg/compose/convergence.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,11 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
ticker := time.NewTicker(500 * time.Millisecond)
defer ticker.Stop()
for {
<-ticker.C
select {
case <-ticker.C:
case <-ctx.Done():
return nil
}
switch config.Condition {
case ServiceConditionRunningOrHealthy:
healthy, err := s.isServiceHealthy(ctx, waitingFor, true)
Expand Down
15 changes: 13 additions & 2 deletions pkg/progress/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,25 @@ func (w *ttyWriter) Stop() {
func (w *ttyWriter) Event(e Event) {
w.mtx.Lock()
defer w.mtx.Unlock()
w.event(e)
}

func (w *ttyWriter) event(e Event) {
if !utils.StringContains(w.eventIDs, e.ID) {
w.eventIDs = append(w.eventIDs, e.ID)
}
if _, ok := w.events[e.ID]; ok {
last := w.events[e.ID]
switch e.Status {
case Done, Error, Warning:
if last.Status != e.Status {
if last.endTime.IsZero() {
last.stop()
}
case Working:
if !last.endTime.IsZero() {
// already done, don't overwrite
return
}
}
last.Status = e.Status
last.Text = e.Text
Expand All @@ -106,8 +115,10 @@ func (w *ttyWriter) Event(e Event) {
}

func (w *ttyWriter) Events(events []Event) {
w.mtx.Lock()
defer w.mtx.Unlock()
for _, e := range events {
w.Event(e)
w.event(e)
}
}

Expand Down

0 comments on commit 80856ea

Please sign in to comment.