Skip to content

Commit 3c4593f

Browse files
committed
Stop the resource timer after last expected event
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent d256202 commit 3c4593f

File tree

10 files changed

+54
-16
lines changed

10 files changed

+54
-16
lines changed

pkg/compose/convergence.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ func (s *composeService) isServiceCompleted(ctx context.Context, containers Cont
737737
return false, 0, nil
738738
}
739739

740-
func (s *composeService) startService(ctx context.Context, project *types.Project, service types.ServiceConfig, containers Containers) error {
740+
func (s *composeService) startService(ctx context.Context, project *types.Project, service types.ServiceConfig, containers Containers, wait bool) error {
741741
if service.Deploy != nil && service.Deploy.Replicas != nil && *service.Deploy.Replicas == 0 {
742742
return nil
743743
}
@@ -765,11 +765,28 @@ func (s *composeService) startService(ctx context.Context, project *types.Projec
765765
if err != nil {
766766
return err
767767
}
768-
w.Event(progress.StartedEvent(eventName))
768+
status := progress.Done
769+
if wait || dependencyWaiting(project, service.Name) {
770+
status = progress.Working
771+
}
772+
w.Event(progress.NewEvent(eventName, status, "Started"))
769773
}
770774
return nil
771775
}
772776

777+
func dependencyWaiting(project *types.Project, name string) bool {
778+
for _, service := range project.Services {
779+
depends, ok := service.DependsOn[name]
780+
if !ok {
781+
continue
782+
}
783+
if depends.Condition == types.ServiceConditionHealthy {
784+
return true
785+
}
786+
}
787+
return false
788+
}
789+
773790
func mergeLabels(ls ...types.Labels) types.Labels {
774791
merged := types.Labels{}
775792
for _, l := range ls {

pkg/compose/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (s *composeService) start(ctx context.Context, projectName string, options
129129
return err
130130
}
131131

132-
return s.startService(ctx, project, service, containers)
132+
return s.startService(ctx, project, service, containers, options.Wait)
133133
})
134134
if err != nil {
135135
return err

pkg/compose/up.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ import (
3333

3434
func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error { //nolint:gocyclo
3535
err := progress.Run(ctx, tracing.SpanWrapFunc("project/up", tracing.ProjectOptions(project), func(ctx context.Context) error {
36+
w := progress.ContextWriter(ctx)
37+
w.HasMore(options.Start.Attach == nil)
3638
err := s.create(ctx, project, options.Create)
3739
if err != nil {
3840
return err
3941
}
4042
if options.Start.Attach == nil {
43+
w.HasMore(false)
4144
return s.start(ctx, project.Name, options.Start, nil)
4245
}
4346
return nil

pkg/progress/event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,6 @@ func (e *Event) Spinner() any {
191191
case Error:
192192
return ErrorColor(spinnerError)
193193
default:
194-
return e.spinner.String()
194+
return CountColor(e.spinner.String())
195195
}
196196
}

pkg/progress/noop.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ func (p *noopWriter) TailMsgf(_ string, _ ...interface{}) {
3838

3939
func (p *noopWriter) Stop() {
4040
}
41+
42+
func (p *noopWriter) HasMore(bool) {
43+
}

pkg/progress/plain.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,6 @@ func (p *plainWriter) TailMsgf(msg string, args ...interface{}) {
6464
func (p *plainWriter) Stop() {
6565
p.done <- true
6666
}
67+
68+
func (p *plainWriter) HasMore(bool) {
69+
}

pkg/progress/quiet.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ func (q quiet) Events(_ []Event) {
3535

3636
func (q quiet) TailMsgf(_ string, _ ...interface{}) {
3737
}
38+
39+
func (q quiet) HasMore(bool) {
40+
}

pkg/progress/tty.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@ import (
3333
)
3434

3535
type ttyWriter struct {
36-
out io.Writer
37-
events map[string]Event
38-
eventIDs []string
39-
repeated bool
40-
numLines int
41-
done chan bool
42-
mtx *sync.Mutex
43-
tailEvents []string
44-
dryRun bool
45-
skipChildEvents bool
46-
progressTitle string
36+
out io.Writer
37+
events map[string]Event
38+
eventIDs []string
39+
repeated bool
40+
numLines int
41+
done chan bool
42+
mtx *sync.Mutex
43+
tailEvents []string
44+
dryRun bool
45+
skipChildEvents bool
46+
progressTitle string
47+
hasFollowupAction bool
4748
}
4849

4950
func (w *ttyWriter) Start(ctx context.Context) error {
@@ -70,6 +71,10 @@ func (w *ttyWriter) Stop() {
7071
w.done <- true
7172
}
7273

74+
func (w *ttyWriter) HasMore(b bool) {
75+
w.hasFollowupAction = b
76+
}
77+
7378
func (w *ttyWriter) Event(e Event) {
7479
w.mtx.Lock()
7580
defer w.mtx.Unlock()
@@ -82,6 +87,9 @@ func (w *ttyWriter) event(e Event) {
8287
}
8388
if _, ok := w.events[e.ID]; ok {
8489
last := w.events[e.ID]
90+
if e.Status == Done && w.hasFollowupAction {
91+
e.Status = Working
92+
}
8593
switch e.Status {
8694
case Done, Error, Warning:
8795
if last.endTime.IsZero() {

pkg/progress/tty_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestLineText(t *testing.T) {
4242
lineWidth := len(fmt.Sprintf("%s %s", ev.ID, ev.Text))
4343

4444
out := tty().lineText(ev, "", 50, lineWidth, false)
45-
assert.Equal(t, out, " . id Text Status \x1b[34m0.0s \x1b[0m\n")
45+
assert.Equal(t, out, " \x1b[33m.\x1b[0m id Text Status \x1b[34m0.0s \x1b[0m\n")
4646

4747
ev.Status = Done
4848
out = tty().lineText(ev, "", 50, lineWidth, false)

pkg/progress/writer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type Writer interface {
3636
Event(Event)
3737
Events([]Event)
3838
TailMsgf(string, ...interface{})
39+
HasMore(more bool)
3940
}
4041

4142
type writerKey struct{}

0 commit comments

Comments
 (0)