mirror of https://github.com/docker/compose.git
Merge pull request #6452 from docker/collin5-b6446
Fix failure check in parallel_execute_watch
This commit is contained in:
commit
cf96fcb4af
|
@ -43,15 +43,14 @@ class GlobalLimit(object):
|
|||
cls.global_limiter = Semaphore(value)
|
||||
|
||||
|
||||
def parallel_execute_watch(events, writer, errors, results, msg, get_name):
|
||||
def parallel_execute_watch(events, writer, errors, results, msg, get_name, fail_check):
|
||||
""" Watch events from a parallel execution, update status and fill errors and results.
|
||||
Returns exception to re-raise.
|
||||
"""
|
||||
error_to_reraise = None
|
||||
for obj, result, exception in events:
|
||||
if exception is None:
|
||||
if callable(getattr(obj, 'containers', None)) and not obj.containers():
|
||||
# If service has no containers started
|
||||
if fail_check is not None and fail_check(obj):
|
||||
writer.write(msg, get_name(obj), 'failed', red)
|
||||
else:
|
||||
writer.write(msg, get_name(obj), 'done', green)
|
||||
|
@ -76,12 +75,14 @@ def parallel_execute_watch(events, writer, errors, results, msg, get_name):
|
|||
return error_to_reraise
|
||||
|
||||
|
||||
def parallel_execute(objects, func, get_name, msg, get_deps=None, limit=None):
|
||||
def parallel_execute(objects, func, get_name, msg, get_deps=None, limit=None, fail_check=None):
|
||||
"""Runs func on objects in parallel while ensuring that func is
|
||||
ran on object only after it is ran on all its dependencies.
|
||||
|
||||
get_deps called on object must return a collection with its dependencies.
|
||||
get_name called on object must return its name.
|
||||
fail_check is an additional failure check for cases that should display as a failure
|
||||
in the CLI logs, but don't raise an exception (such as attempting to start 0 containers)
|
||||
"""
|
||||
objects = list(objects)
|
||||
stream = get_output_stream(sys.stderr)
|
||||
|
@ -100,7 +101,9 @@ def parallel_execute(objects, func, get_name, msg, get_deps=None, limit=None):
|
|||
|
||||
errors = {}
|
||||
results = []
|
||||
error_to_reraise = parallel_execute_watch(events, writer, errors, results, msg, get_name)
|
||||
error_to_reraise = parallel_execute_watch(
|
||||
events, writer, errors, results, msg, get_name, fail_check
|
||||
)
|
||||
|
||||
for obj_name, error in errors.items():
|
||||
stream.write("\nERROR: for {} {}\n".format(obj_name, error))
|
||||
|
|
|
@ -280,6 +280,7 @@ class Project(object):
|
|||
operator.attrgetter('name'),
|
||||
'Starting',
|
||||
get_deps,
|
||||
fail_check=lambda obj: not obj.containers(),
|
||||
)
|
||||
|
||||
return containers
|
||||
|
|
|
@ -610,6 +610,8 @@ class CLITestCase(DockerClientTestCase):
|
|||
result = self.dispatch(['pull'])
|
||||
assert 'Pulling simple' in result.stderr
|
||||
assert 'Pulling another' in result.stderr
|
||||
assert 'done' in result.stderr
|
||||
assert 'failed' not in result.stderr
|
||||
|
||||
def test_pull_with_digest(self):
|
||||
result = self.dispatch(['-f', 'digest.yml', 'pull', '--no-parallel'])
|
||||
|
|
Loading…
Reference in New Issue