Story 6
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"""Insert processing audit log entries within an existing DB transaction."""
|
||||
|
||||
import json
|
||||
import logging
|
||||
from datetime import datetime, timezone
|
||||
from typing import List, Optional
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def insert_log(
|
||||
cursor,
|
||||
video_id: int,
|
||||
model_version: str,
|
||||
frame_count: int,
|
||||
confidence_score: Optional[float],
|
||||
routing_decision: str,
|
||||
frame_confidences: Optional[List[float]] = None,
|
||||
) -> None:
|
||||
"""Insert one row into processing_logs; must be called inside an open transaction."""
|
||||
now = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
confidence_scores_json = json.dumps(frame_confidences) if frame_confidences is not None else None
|
||||
|
||||
cursor.execute(
|
||||
"""INSERT INTO processing_logs
|
||||
(video_id, model_version, frame_count, confidence_score,
|
||||
confidence_scores, routing_decision, processed_at)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s)""",
|
||||
(
|
||||
video_id,
|
||||
model_version,
|
||||
frame_count or 0,
|
||||
confidence_score,
|
||||
confidence_scores_json,
|
||||
routing_decision,
|
||||
now,
|
||||
),
|
||||
)
|
||||
logger.debug("Inserted processing log for video %s (routing=%s)", video_id, routing_decision)
|
||||
Reference in New Issue
Block a user