Cycle: answer each measure's latest periods after a run, so the first reader finds them stored

This commit is contained in:
Roberto Treviño Cervantes
2026-11-23 00:06:33 -06:00
parent 1048175531
commit bd8c7aa55a
2 changed files with 41 additions and 0 deletions
+17
View File
@@ -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)