From 9629ca595d88264c079ac4b8a87ec7aed67f478f Mon Sep 17 00:00:00 2001 From: Robert Helewka Date: Fri, 15 May 2026 10:50:35 -0400 Subject: [PATCH] refactor(startup): move startup probe to gunicorn worker init Move probe execution from Django app ready() to gunicorn.conf.py Remove threading implementation to simplify startup sequence Ensure probe runs in worker process context with proper error handling --- docker/gunicorn.conf.py | 9 +++++++++ mnemosyne/library/apps.py | 15 +-------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/docker/gunicorn.conf.py b/docker/gunicorn.conf.py index c91eaa8..f86de35 100644 --- a/docker/gunicorn.conf.py +++ b/docker/gunicorn.conf.py @@ -25,3 +25,12 @@ def on_starting(server): def post_worker_init(worker): logging.getLogger("gunicorn.access").addFilter(_filter) + from library.apps import _run_startup_probe, _should_skip_probe + + if not _should_skip_probe(): + try: + _run_startup_probe() + except Exception as exc: + logging.getLogger("library.apps").warning( + "Startup probe crashed: %s", exc, exc_info=True + ) diff --git a/mnemosyne/library/apps.py b/mnemosyne/library/apps.py index 3995e95..2a39b5b 100644 --- a/mnemosyne/library/apps.py +++ b/mnemosyne/library/apps.py @@ -199,17 +199,4 @@ class LibraryConfig(AppConfig): verbose_name = "Library" def ready(self): - if _should_skip_probe(): - return - import threading - - t = threading.Thread(target=self._probe_thread, daemon=True) - t.start() - t.join(timeout=10) - - def _probe_thread(self): - try: - _run_startup_probe() - except Exception as exc: - # Never let the probe itself take down the process. - logger.warning("Startup probe crashed: %s", exc, exc_info=True) + pass