add import audit trail, live indicator recompute, reportes endpoints; production hardening
This commit is contained in:
+12
-22
@@ -3,8 +3,8 @@
|
||||
A successful import asks for a recomputation (`ColaDeRecalculo.solicitar`),
|
||||
which only drops a marker file. A separate process (`python -m
|
||||
webapi.indicadores_vivos`, the `indicadores` compose service) picks the
|
||||
markers up and runs that domain's pipeline with Hamilton (`webapi.pipeline`):
|
||||
catalogs -> staging to facts -> views -> registry -> definitions -> reports.
|
||||
markers up and runs that domain's cycle (`orquestacion.correr`): catalogs ->
|
||||
staging to facts -> views -> registry -> definitions -> reports.
|
||||
Requests that arrive while a domain is running are folded into one more run.
|
||||
|
||||
State lives in files under `INDICADORES_DIR`: `pendiente/<dominio>` markers
|
||||
@@ -18,6 +18,7 @@ import json
|
||||
import logging
|
||||
import os
|
||||
import signal
|
||||
import threading
|
||||
import time
|
||||
from datetime import date, datetime, timezone
|
||||
from pathlib import Path
|
||||
@@ -97,10 +98,7 @@ class ColaDeRecalculo:
|
||||
|
||||
def correr(self, dominio: str, *, desde: int | None = None, hasta: int | None = None) -> dict[str, Any]:
|
||||
"""Runs the domain's graph (without `migrar`: the API migrates on startup)."""
|
||||
from orquestacion import Contexto
|
||||
from orquestacion.aristas import aristas_de
|
||||
|
||||
from webapi.pipeline import correr
|
||||
from orquestacion import Contexto, correr, pasos_de
|
||||
|
||||
desde = desde or int(os.environ.get("INDICADORES_DESDE", date.today().year - 5))
|
||||
hasta = hasta or int(os.environ.get("INDICADORES_HASTA", date.today().year))
|
||||
@@ -110,11 +108,10 @@ class ColaDeRecalculo:
|
||||
entrada: dict[str, Any] = {"inicio": inicio, "anios": [desde, hasta]}
|
||||
try:
|
||||
ctx = Contexto(dominio, desde, hasta, permitir_sin_definir=True)
|
||||
nombres = [a.nombre for a in aristas_de(dominio) if a.nombre != "migrar"]
|
||||
pasos = correr(ctx, solo=nombres)
|
||||
pasos = correr(ctx, solo=[p for p in pasos_de(dominio) if p != "migrar"])
|
||||
entrada.update(
|
||||
estado="ok",
|
||||
pasos=[{"arista": p.arista, "segundos": round(p.segundos, 2), "resumen": _short(p.resumen)} for p in pasos],
|
||||
pasos=[{"paso": p.nombre, "segundos": round(p.segundos, 2), "resumen": _short(p.resumen)} for p in pasos],
|
||||
)
|
||||
except Exception as exc: # the worker must survive a failing domain
|
||||
log.exception("recálculo de %s falló", dominio)
|
||||
@@ -144,22 +141,15 @@ def main() -> None:
|
||||
if os.environ.get("INDICADORES_AL_INICIAR", "1") == "1":
|
||||
for dominio in DOMINIOS:
|
||||
cola.solicitar(dominio)
|
||||
stopping = False
|
||||
|
||||
def _stop(*_):
|
||||
nonlocal stopping
|
||||
stopping = True
|
||||
|
||||
signal.signal(signal.SIGTERM, _stop)
|
||||
signal.signal(signal.SIGINT, _stop)
|
||||
stop = threading.Event()
|
||||
signal.signal(signal.SIGTERM, lambda *_: stop.set())
|
||||
signal.signal(signal.SIGINT, lambda *_: stop.set())
|
||||
log.info("indicadores en vivo: revisando cada %.0f s en %s", interval, cola.base)
|
||||
while not stopping:
|
||||
while True:
|
||||
for dominio in cola.atender():
|
||||
log.info("%s: %s", dominio, cola.estado()[dominio].get("estado"))
|
||||
for _ in range(int(interval * 10)):
|
||||
if stopping:
|
||||
break
|
||||
time.sleep(0.1)
|
||||
if stop.wait(interval):
|
||||
break
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user