Forráskód Böngészése

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]>
Nikhil Benesch 3 éve
szülő
commit
5eb314a4ca
2 módosított fájl, 38 hozzáadás és 3 törlés
  1. 23 3
      pkg/compose/convergence.go
  2. 15 0
      pkg/progress/event.go

+ 23 - 3
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

+ 15 - 0
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")