Skip to content

Commit

Permalink
Merge pull request #19 from betatim/non-blocking
Browse files Browse the repository at this point in the history
Fix blocking call to docker build log
  • Loading branch information
betatim committed Sep 24, 2015
2 parents 42845c5 + fb93101 commit 4d5f867
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions everware/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from tempfile import mkdtemp
from datetime import timedelta

from concurrent.futures import ThreadPoolExecutor

from docker.errors import APIError

from dockerspawner import DockerSpawner
Expand All @@ -21,6 +23,21 @@ class CustomDockerSpawner(DockerSpawner):
def __init__(self, **kwargs):
super(CustomDockerSpawner, self).__init__(**kwargs)

def _docker(self, method, *args, **kwargs):
"""wrapper for calling docker methods
to be passed to ThreadPoolExecutor
"""
# methods that return a generator object return instantly
# before the work they were meant to do is complete
generator_methods = ('build',)
m = getattr(self.client, method)

if method in generator_methods:
return list(m(*args, **kwargs))
else:
return m(*args, **kwargs)

_git_executor = None
@property
def git_executor(self):
Expand Down Expand Up @@ -52,7 +69,7 @@ def git(self, method, *args, **kwargs):
returns a Future
"""
return self.executor.submit(self._git, method, *args, **kwargs)
return self.git_executor.submit(self._git, method, *args, **kwargs)

@property
def repo_url(self):
Expand Down Expand Up @@ -113,7 +130,6 @@ def start(self, image=None):
tag=image_name,
rm=True)
self.log.debug("".join(str(line) for line in build_log))
self.log.info("Built docker image {}".format(image_name))

images = yield self.docker('images', image_name)
self.log.debug(images)
Expand Down

0 comments on commit 4d5f867

Please sign in to comment.