Skip to content

Commit

Permalink
Increase logging verbosity.
Browse files Browse the repository at this point in the history
  • Loading branch information
csadorf committed Feb 17, 2022
1 parent af1a621 commit 9774e8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions aiidalab_launch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ async def _async_start(
echo_logs = asyncio.create_task(instance.echo_logs())
await asyncio.wait_for(instance.wait_for_services(), timeout=wait)
echo_logs.cancel()
LOGGER.debug("AiiDAlab instance ready.")
except asyncio.TimeoutError:
raise click.ClickException(
f"AiiDAlab instance did not start up within the provided wait period ({wait})."
Expand All @@ -404,6 +405,7 @@ async def _async_start(
"the container output logs by increasing the output "
"verbosity with 'aiidalab-launch -vvv start'."
)
LOGGER.debug("Preparing startup message.")
msg_startup = (
MSG_STARTUP_SSH
if (show_ssh_help or not webbrowser_available())
Expand Down
14 changes: 12 additions & 2 deletions aiidalab_launch/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pathlib import Path, PurePosixPath
from secrets import token_hex
from shutil import rmtree
from time import time
from typing import Any, AsyncGenerator, Generator

import docker
Expand Down Expand Up @@ -196,6 +197,7 @@ def _run_post_start(self) -> None:
LOGGER.warn(
"Failed to ensure ~/.conda directory is owned by the system user."
)
LOGGER.debug("The ~/.conda directory is owned by the system user.")

def stop(self, timeout: float | None = None) -> None:
self._requires_container()
Expand Down Expand Up @@ -268,26 +270,28 @@ async def echo_logs(self) -> None:
async def _init_scripts_finished(self) -> None:
assert self.container is not None
loop = asyncio.get_event_loop()
LOGGER.info("Waiting for init services to finish...")
LOGGER.debug("Waiting for init services to finish...")
result = await loop.run_in_executor(
None, self.container.exec_run, "wait-for-services"
)
if result.exit_code != 0:
raise FailedToWaitForServices(
"Failed to check for init processes to complete."
)
LOGGER.debug("Init services finished.")

async def _notebook_service_online(self) -> None:
assert self.container is not None
loop = asyncio.get_event_loop()
LOGGER.info("Waiting for notebook service to become reachable...")
LOGGER.debug("Waiting for notebook service to become reachable...")
while True:
result = await loop.run_in_executor(
None,
self.container.exec_run,
"curl --fail-early --fail --silent --max-time 1.0 http://localhost:8888",
)
if result.exit_code == 0:
LOGGER.debug("Notebook service reachable.")
return # jupyter is online
elif result.exit_code in (7, 28):
await asyncio.sleep(1) # jupyter not yet reachable
Expand All @@ -298,9 +302,11 @@ async def _notebook_service_online(self) -> None:
async def _host_port_assigned(self) -> None:
container = self.container
assert container is not None
LOGGER.debug("Waiting for host port to be assigned...")
while True:
container.reload()
if any(_get_host_ports(container)):
LOGGER.debug("Host port assigned.")
break
asyncio.sleep(1)

Expand All @@ -309,11 +315,15 @@ async def wait_for_services(self) -> None:
raise RuntimeError("Instance was not created.")

LOGGER.info(f"Waiting for services to come up ({self.container.id})...")
start = time()
await asyncio.gather(
self._init_scripts_finished(),
self._notebook_service_online(),
self._host_port_assigned(),
)
LOGGER.info(
f"Services came up after {time() - start:.1f} seconds ({self.container.id})."
)

async def status(self, timeout: float | None = 5.0) -> AiidaLabInstanceStatus:
if self.container:
Expand Down

0 comments on commit 9774e8c

Please sign in to comment.