mirror of
https://github.com/docker/compose.git
synced 2025-07-24 14:14:35 +02:00
fix cyclomatic complexity of composeService.waitDependencies function
Signed-off-by: Guillaume Lours <guillaume.lours@docker.com>
This commit is contained in:
parent
4be38f84df
commit
64a9e4bf01
@ -276,14 +276,9 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
|
|||||||
eg, _ := errgroup.WithContext(ctx)
|
eg, _ := errgroup.WithContext(ctx)
|
||||||
w := progress.ContextWriter(ctx)
|
w := progress.ContextWriter(ctx)
|
||||||
for dep, config := range dependencies {
|
for dep, config := range dependencies {
|
||||||
if config.Condition == types.ServiceConditionStarted {
|
if shouldWait, err := shouldWaitForDependency(dep, config, project); err != nil {
|
||||||
// already managed by InDependencyOrder
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if service, err := project.GetService(dep); err != nil {
|
|
||||||
return err
|
return err
|
||||||
} else if service.Scale == 0 {
|
} else if !shouldWait {
|
||||||
// don't wait for the dependency which configured to have 0 containers running
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,6 +335,20 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
|
|||||||
return eg.Wait()
|
return eg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shouldWaitForDependency(serviceName string, dependencyConfig types.ServiceDependency, project *types.Project) (bool, error) {
|
||||||
|
if dependencyConfig.Condition == types.ServiceConditionStarted {
|
||||||
|
// already managed by InDependencyOrder
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
if service, err := project.GetService(serviceName); err != nil {
|
||||||
|
return false, err
|
||||||
|
} else if service.Scale == 0 {
|
||||||
|
// don't wait for the dependency which configured to have 0 containers running
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
func nextContainerNumber(containers []moby.Container) (int, error) {
|
func nextContainerNumber(containers []moby.Container) (int, error) {
|
||||||
max := 0
|
max := 0
|
||||||
for _, c := range containers {
|
for _, c := range containers {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user