add import audit trail, live indicator recompute, reportes endpoints; production hardening
This commit is contained in:
+6
-15
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user