Skip to content

Commit 5eb314a

Browse files
beneschndeloof
authored andcommitted
Add progress output while waiting for dependencies
This commit adds progress output while waiting for `depends_on` conditions to resolve. The initial output looks like so: ⠿ Container chbench-zookeeper-1 Waiting 0s ⠿ Container chbench-kafka-1 Waiting 0s ⠿ Container chbench-one-off Waiting 0s Once all conditions have been resolved, the ouput looks like this: ⠿ Container chbench-zookeeper-1 Healthy 1.2s ⠿ Container chbench-kafka-1 Healthy 3.2s ⠿ Container chbench-schema-registry-1 Exited 4s As shown above, `service_healthy` conditions result in a terminal status of "Healthy" while `service_exited_successfully` conditions result in a terminal status of "Exited". Signed-off-by: Nikhil Benesch <[email protected]>
1 parent c5cdce0 commit 5eb314a

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

pkg/compose/convergence.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,21 @@ const ServiceConditionRunningOrHealthy = "running_or_healthy"
266266

267267
func (s *composeService) waitDependencies(ctx context.Context, project *types.Project, dependencies types.DependsOnConfig) error {
268268
eg, _ := errgroup.WithContext(ctx)
269+
w := progress.ContextWriter(ctx)
269270
for dep, config := range dependencies {
271+
if config.Condition == types.ServiceConditionStarted {
272+
// already managed by InDependencyOrder
273+
return nil
274+
}
275+
276+
containers, err := s.getContainers(ctx, project.Name, oneOffExclude, false, dep)
277+
if err != nil {
278+
return err
279+
}
280+
for _, container := range containers {
281+
w.Event(progress.Waiting(getContainerProgressName(container)))
282+
}
283+
270284
dep, config := dep, config
271285
eg.Go(func() error {
272286
ticker := time.NewTicker(500 * time.Millisecond)
@@ -280,6 +294,9 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
280294
return err
281295
}
282296
if healthy {
297+
for _, container := range containers {
298+
w.Event(progress.Healthy(getContainerProgressName(container)))
299+
}
283300
return nil
284301
}
285302
case types.ServiceConditionHealthy:
@@ -288,6 +305,9 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
288305
return err
289306
}
290307
if healthy {
308+
for _, container := range containers {
309+
w.Event(progress.Healthy(getContainerProgressName(container)))
310+
}
291311
return nil
292312
}
293313
case types.ServiceConditionCompletedSuccessfully:
@@ -296,14 +316,14 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
296316
return err
297317
}
298318
if exited {
319+
for _, container := range containers {
320+
w.Event(progress.Exited(getContainerProgressName(container)))
321+
}
299322
if code != 0 {
300323
return fmt.Errorf("service %q didn't completed successfully: exit %d", dep, code)
301324
}
302325
return nil
303326
}
304-
case types.ServiceConditionStarted:
305-
// already managed by InDependencyOrder
306-
return nil
307327
default:
308328
logrus.Warnf("unsupported depends_on condition: %s", config.Condition)
309329
return nil

pkg/progress/event.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ func StartedEvent(ID string) Event {
6868
return NewEvent(ID, Done, "Started")
6969
}
7070

71+
// Waiting creates a new waiting event
72+
func Waiting(ID string) Event {
73+
return NewEvent(ID, Working, "Waiting")
74+
}
75+
76+
// Healthy creates a new healthy event
77+
func Healthy(ID string) Event {
78+
return NewEvent(ID, Done, "Healthy")
79+
}
80+
81+
// Exited creates a new exited event
82+
func Exited(ID string) Event {
83+
return NewEvent(ID, Done, "Exited")
84+
}
85+
7186
// RestartingEvent creates a new Restarting in progress Event
7287
func RestartingEvent(ID string) Event {
7388
return NewEvent(ID, Working, "Restarting")

0 commit comments

Comments
 (0)