From 5eb314a4cafa2433aa5b226bbfa714902743bb8b Mon Sep 17 00:00:00 2001 From: Nikhil Benesch Date: Thu, 6 Jan 2022 23:17:10 -0500 Subject: [PATCH] Add progress output while waiting for dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- pkg/compose/convergence.go | 26 +++++++++++++++++++++++--- pkg/progress/event.go | 15 +++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/pkg/compose/convergence.go b/pkg/compose/convergence.go index 7eb40793..401abbe4 100644 --- a/pkg/compose/convergence.go +++ b/pkg/compose/convergence.go @@ -266,7 +266,21 @@ const ServiceConditionRunningOrHealthy = "running_or_healthy" func (s *composeService) waitDependencies(ctx context.Context, project *types.Project, dependencies types.DependsOnConfig) error { eg, _ := errgroup.WithContext(ctx) + w := progress.ContextWriter(ctx) for dep, config := range dependencies { + if config.Condition == types.ServiceConditionStarted { + // already managed by InDependencyOrder + return nil + } + + containers, err := s.getContainers(ctx, project.Name, oneOffExclude, false, dep) + if err != nil { + return err + } + for _, container := range containers { + w.Event(progress.Waiting(getContainerProgressName(container))) + } + dep, config := dep, config eg.Go(func() error { ticker := time.NewTicker(500 * time.Millisecond) @@ -280,6 +294,9 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr return err } if healthy { + for _, container := range containers { + w.Event(progress.Healthy(getContainerProgressName(container))) + } return nil } case types.ServiceConditionHealthy: @@ -288,6 +305,9 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr return err } if healthy { + for _, container := range containers { + w.Event(progress.Healthy(getContainerProgressName(container))) + } return nil } case types.ServiceConditionCompletedSuccessfully: @@ -296,14 +316,14 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr return err } if exited { + for _, container := range containers { + w.Event(progress.Exited(getContainerProgressName(container))) + } if code != 0 { return fmt.Errorf("service %q didn't completed successfully: exit %d", dep, code) } return nil } - case types.ServiceConditionStarted: - // already managed by InDependencyOrder - return nil default: logrus.Warnf("unsupported depends_on condition: %s", config.Condition) return nil diff --git a/pkg/progress/event.go b/pkg/progress/event.go index 979a0e53..5a013a8b 100644 --- a/pkg/progress/event.go +++ b/pkg/progress/event.go @@ -68,6 +68,21 @@ func StartedEvent(ID string) Event { return NewEvent(ID, Done, "Started") } +// Waiting creates a new waiting event +func Waiting(ID string) Event { + return NewEvent(ID, Working, "Waiting") +} + +// Healthy creates a new healthy event +func Healthy(ID string) Event { + return NewEvent(ID, Done, "Healthy") +} + +// Exited creates a new exited event +func Exited(ID string) Event { + return NewEvent(ID, Done, "Exited") +} + // RestartingEvent creates a new Restarting in progress Event func RestartingEvent(ID string) Event { return NewEvent(ID, Working, "Restarting")