add import audit trail, live indicator recompute, reportes endpoints; production hardening

This commit is contained in:
Roberto Treviño Cervantes
2026-10-30 11:19:30 -06:00
parent 168edb30f5
commit 2b2c290f58
74 changed files with 4095 additions and 1782 deletions
+6 -15
View File
@@ -8,8 +8,8 @@ A rejected catalog value is written verbatim only when at least
`WEBAPI_REPORT_MIN_COUNT` rows share it, so a rare (identifying) value never
appears.
`ImportAudit` collects the facts while the import runs; an `AuditSink`
decides where the finished record goes.
`ImportAudit` collects the facts while the import runs; `JsonlAuditSink`
appends the finished record.
"""
from __future__ import annotations
@@ -19,7 +19,6 @@ import os
import re
import time
import uuid
from abc import ABC, abstractmethod
from collections import Counter, defaultdict
from dataclasses import dataclass, field
from datetime import datetime, timezone
@@ -246,15 +245,7 @@ class ImportAudit:
return record
class AuditSink(ABC):
@abstractmethod
def write(self, record: dict[str, Any]) -> None: ...
@abstractmethod
def read(self) -> list[dict[str, Any]]: ...
class JsonlAuditSink(AuditSink):
class JsonlAuditSink:
"""One JSON object per line; appends are locked so several gunicorn
workers can share the file."""
@@ -287,14 +278,14 @@ class JsonlAuditSink(AuditSink):
return records
def default_sink() -> AuditSink:
def default_sink() -> JsonlAuditSink:
return JsonlAuditSink(report_dir() / "importaciones.jsonl")
def record(audit: ImportAudit, sink: AuditSink | None = None) -> None:
def record(audit: ImportAudit) -> None:
"""Writes the record; a full disk must not turn a successful import into an error."""
try:
(sink or default_sink()).write(audit.as_dict())
default_sink().write(audit.as_dict())
except OSError:
pass