Merge pull request #1714 from aanand/scale-timeout

Make scale timeout configurable, default to 10
This commit is contained in:
Aanand Prasad 2015-07-17 10:13:30 +01:00
commit b2cb5a48d2
2 changed files with 10 additions and 4 deletions

View File

@ -372,8 +372,14 @@ class TopLevelCommand(Command):
$ docker-compose scale web=2 worker=3
Usage: scale [SERVICE=NUM...]
Usage: scale [options] [SERVICE=NUM...]
Options:
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
(default: 10)
"""
timeout = int(options.get('--timeout') or DEFAULT_TIMEOUT)
for s in options['SERVICE=NUM']:
if '=' not in s:
raise UserError('Arguments to scale should be in the form service=num')
@ -383,7 +389,7 @@ class TopLevelCommand(Command):
except ValueError:
raise UserError('Number of containers for service "%s" is not a '
'number' % service_name)
project.get_service(service_name).scale(num)
project.get_service(service_name).scale(num, timeout=timeout)
def start(self, project, options):
"""

View File

@ -147,7 +147,7 @@ class Service(object):
# end TODO
def scale(self, desired_num):
def scale(self, desired_num, timeout=DEFAULT_TIMEOUT):
"""
Adjusts the number of containers to the specified number and ensures
they are running.
@ -181,7 +181,7 @@ class Service(object):
while len(running_containers) > desired_num:
c = running_containers.pop()
log.info("Stopping %s..." % c.name)
c.stop(timeout=1)
c.stop(timeout=timeout)
stopped_containers.append(c)
# Start containers