Live models: the labelled members are saved once per build and version, prepared by the indicators cycle and loaded by each API worker as it starts

This commit is contained in:
Roberto Treviño Cervantes
2026-11-22 22:02:04 -06:00
parent f7f8af8b4c
commit f97d1202a9
5 changed files with 119 additions and 3 deletions
+19
View File
@@ -1,4 +1,5 @@
import datetime as _dt
import logging
import os
from decimal import Decimal
@@ -111,4 +112,22 @@ def create_app() -> Flask:
app.register_blueprint(model_analysis_blueprint("cama", "survival"), url_prefix="/cama")
app.register_blueprint(recurrence_blueprint(), url_prefix="/cama")
if os.environ.get("WEBAPI_PRECALENTAR_MODELOS") == "1":
_warm_in_background()
return app
def _warm_in_background() -> None:
"""Loads the live models' members in each worker as it starts, so the first patient opened doesn't wait for them."""
import threading
from webapi.model_analysis import LIVE_SCENARIOS, warm
def run():
for domain in LIVE_SCENARIOS:
try:
warm(domain)
except Exception: # the request that needs them will try again and say why
logging.getLogger(__name__).exception("no se pudieron precargar los modelos de %s", domain)
threading.Thread(target=run, name="precarga-modelos", daemon=True).start()