From 83f192bc0069a370ee3a86d6410da56bea342bdf Mon Sep 17 00:00:00 2001 From: Nick Ninov Date: Thu, 18 Jun 2026 07:39:20 +0300 Subject: [PATCH] docker: Sleep after run finishes - Sleep prevents calling `Account` faster than launching the docker container. This only happens when the container already exists and it is must be turned on. - Add logs --- bot/utils.py | 17 ++++++++++++++--- docs/utils.md | 8 ++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/bot/utils.py b/bot/utils.py index 0537990..27b7c9b 100644 --- a/bot/utils.py +++ b/bot/utils.py @@ -1,14 +1,21 @@ -import shutil, os, subprocess, sys +import shutil, os, subprocess, sys, time from pathlib import Path +from .logger import Logger -def launch_docker_container(): +def launch_docker_container(wait_seconds: int = 5): """ Launch the Status Backend Docker container using `docker-compose.yaml` + + Parameters: + - `wait_seconds` - nunmber of seconds to wait before the code resumes. Sleep prevents calling `class Account` faster than launching the docker container. This only happens when the container already exists and it is must be turned on. """ - is_windows = sys.platform == "win32" + logger = Logger() + platform = sys.platform + is_windows = platform == "win32" if not shutil.which("docker"): raise Exception("Please install Docker.") + logger.info(f"Running Docker on {platform}") DOCKER_COMPOSE_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "docker-compose.yaml") docker_path = DOCKER_COMPOSE_PATH if is_windows: @@ -22,6 +29,7 @@ def launch_docker_container(): raise Exception("Please install wsl - https://learn.microsoft.com/en-us/windows/wsl/install.") cmd.insert(0, "wsl") + logger.info(f"Running:\n{' '.join(cmd)}") result = subprocess.run( cmd, cwd=os.path.dirname(DOCKER_COMPOSE_PATH), @@ -31,3 +39,6 @@ def launch_docker_container(): if result.returncode != 0: raise Exception(result.stderr.strip()) + + logger.info(f"Sleeping for {wait_seconds}s") + time.sleep(wait_seconds) diff --git a/docs/utils.md b/docs/utils.md index 49b998a..b1b9729 100644 --- a/docs/utils.md +++ b/docs/utils.md @@ -6,14 +6,18 @@ Helper functions for setting up the Status Backend environment. ## Methods -### `launch_docker_container()` +### `launch_docker_container(wait_seconds=5)` Launch Status Backend Docker container in the background using `docker-compose.yaml`. If `docker` is not installed, or if the container fails to start, an **exception will be raised** with the error message from Docker. +| Name | Type | Required | Description | +|-----|-----|-----|-------------| +| `wait_seconds` | `int` | No | Number of seconds to pause after the `docker compose up` command returns, giving Status Backend enough time to finish booting before subsequent code runs. Defaults to `5`. This matters mainly when the container already exists and is being restarted, because `docker compose up` returns immediately while the backend is still warming up - instantiating [`Account`](./account.md#accountdomainlocalhost-port8080-is_securefalse-backup_foldernone) too quickly will fail to connect. | + ```python from bot import launch_docker_container -launch_docker_container() +launch_docker_container(wait_seconds=10) ``` **Windows Note**: In Docker go to `Settings > Resources > WSL integration` and make sure `Enable integration with my default WSL distro` and `Ubuntu` are **turned on**.