From 2b17aa5b8fb45a3b764f8fa2ab24315a3824f4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Fri, 20 Oct 2023 11:50:52 +0200 Subject: [PATCH] refac: production mode startup logic --- api/.vscode/launch.json | 3 +++ api/ovdashboard_api/app.py | 16 ++++++++++++---- api/ovdashboard_api/core/settings.py | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index d56e29d..9f9aa0b 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -16,6 +16,9 @@ "PYDEVD_DISABLE_FILE_VALIDATION": "1", "LOG_LEVEL": "DEBUG", "WEBDAV__CACHE_TTL": "30", + // "PRODUCTION_MODE": "true", + // "WEBDAV__RETRIES": "5", + // "WEBDAV__RETRY_DELAY": "1", }, "justMyCode": true } diff --git a/api/ovdashboard_api/app.py b/api/ovdashboard_api/app.py index 1ee443f..648ecc9 100644 --- a/api/ovdashboard_api/app.py +++ b/api/ovdashboard_api/app.py @@ -53,15 +53,23 @@ if SETTINGS.production_mode: name="frontend", ) - for _ in range(SETTINGS.webdav.retries): + def check_webdav(retry: int) -> bool | None: if WebDAV._webdav_client.check(""): - break + return True _logger.warning( - "Waiting for WebDAV connection to %s ...", + "WebDAV connection to %s failed (try %d of %d)", repr(SETTINGS.webdav.url), + retry + 1, + SETTINGS.webdav.retries, ) - time.sleep(30) + + if retry < SETTINGS.webdav.retries: + _logger.debug("Retrying in %d seconds ...", SETTINGS.webdav.retry_delay) + time.sleep(SETTINGS.webdav.retry_delay) + + if not any(check_webdav(n) for n in range(SETTINGS.webdav.retries)): + raise ConnectionError("WebDAV connection failed") else: assert WebDAV._webdav_client.check("") diff --git a/api/ovdashboard_api/core/settings.py b/api/ovdashboard_api/core/settings.py index ceb9e8b..35181a5 100644 --- a/api/ovdashboard_api/core/settings.py +++ b/api/ovdashboard_api/core/settings.py @@ -54,6 +54,7 @@ class WebDAVSettings(DAVSettings): disable_check: bool = False retries: int = 20 + retry_delay: int = 30 prefix: str = "/ovdashboard" @property