Cycle: answer each measure's latest periods after a run, so the first reader finds them stored
This commit is contained in:
@@ -62,6 +62,22 @@ def _warm_models(dominio: str) -> dict[str, Any]:
|
||||
return {"paso": "modelos", "segundos": round(time.monotonic() - started, 2), "resumen": _short(resumen)}
|
||||
|
||||
|
||||
def _answer_measures(dominio: str) -> dict[str, Any]:
|
||||
"""Leaves each measure's latest periods answered with what this run loaded (`webapi.kpis.answer_latest`)."""
|
||||
from importlib import import_module
|
||||
|
||||
from webapi.kpis import answer_latest
|
||||
|
||||
started = time.monotonic()
|
||||
manifest = os.environ.get("DBT_MANIFEST")
|
||||
try:
|
||||
resumen = answer_latest(dominio, import_module(f"persistance.{dominio}"), Path(manifest)) if manifest else "sin DBT_MANIFEST"
|
||||
except Exception as exc: # the indicators are already saved
|
||||
log.exception("no se pudieron responder los indicadores de %s", dominio)
|
||||
resumen = f"error: {type(exc).__name__}"
|
||||
return {"paso": "respuestas", "segundos": round(time.monotonic() - started, 2), "resumen": _short(resumen)}
|
||||
|
||||
|
||||
class RecomputationQueue:
|
||||
"""Marker-file queue and status of the indicator recomputations."""
|
||||
|
||||
@@ -138,6 +154,7 @@ class RecomputationQueue:
|
||||
estado="ok",
|
||||
pasos=[{"paso": p.name, "segundos": round(p.seconds, 2), "resumen": _short(p.summary)} for p in pasos],
|
||||
)
|
||||
entrada["pasos"].append(_answer_measures(dominio))
|
||||
entrada["pasos"].append(_warm_models(dominio))
|
||||
except Exception as exc: # the worker must survive a failing domain
|
||||
log.exception("recálculo de %s falló", dominio)
|
||||
|
||||
Reference in New Issue
Block a user