diff --git a/binderhub/builder.py b/binderhub/builder.py index fdbc391c9..26522cb5b 100644 --- a/binderhub/builder.py +++ b/binderhub/builder.py @@ -447,11 +447,25 @@ async def get(self, provider_prefix, _unescaped_spec): ) with BUILDS_INPROGRESS.track_inprogress(): + done = False + failed = False + + def _check_result(future): + nonlocal done + nonlocal failed + try: + r = future.result() + app_log.debug("task completed: %s", r) + except Exception: + app_log.error("task failed: %s", exc_info=True) + done = True + failed = True + build_starttime = time.perf_counter() pool = self.settings["build_pool"] # Start building submit_future = pool.submit(build.submit) - # TODO: hook up actual error handling when this fails + submit_future.add_done_callback(_check_result) IOLoop.current().add_callback(lambda: submit_future) log_future = None @@ -464,8 +478,6 @@ async def get(self, provider_prefix, _unescaped_spec): } ) - done = False - failed = False while not done: progress = await q.get() @@ -486,6 +498,7 @@ async def get(self, provider_prefix, _unescaped_spec): # start capturing build logs once the pod is running if log_future is None: log_future = pool.submit(build.stream_logs) + log_future.add_done_callback(_check_result) continue elif progress.payload == ProgressEvent.BuildStatus.COMPLETED: # Do nothing, is ok!