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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user