rebuild(migration): validate local legacy cutover
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import json
|
||||
import sqlite3
|
||||
from datetime import datetime, timedelta
|
||||
@@ -147,8 +148,28 @@ def public_job(row: sqlite3.Row) -> dict[str, Any]:
|
||||
result = dict(row)
|
||||
result["source_set"] = json.loads(str(result.pop("source_set_json")))
|
||||
result["payload"] = json.loads(str(result.pop("payload_json")))
|
||||
result["error_message"] = _public_error_message(str(result["error_message"]))
|
||||
return result
|
||||
|
||||
|
||||
def _public_error_message(value: str) -> str:
|
||||
"""Normalize AppError tuples written before structured error storage."""
|
||||
if not value.startswith("("):
|
||||
return value
|
||||
try:
|
||||
legacy = ast.literal_eval(value)
|
||||
except (SyntaxError, ValueError):
|
||||
return value
|
||||
if (
|
||||
isinstance(legacy, tuple)
|
||||
and len(legacy) == 3
|
||||
and isinstance(legacy[0], str)
|
||||
and isinstance(legacy[1], str)
|
||||
and isinstance(legacy[2], int)
|
||||
):
|
||||
return legacy[1]
|
||||
return value
|
||||
|
||||
|
||||
def _json(value: Any) -> str:
|
||||
return json.dumps(value, ensure_ascii=False, separators=(",", ":"), sort_keys=True)
|
||||
|
||||
@@ -57,7 +57,7 @@ class JobService:
|
||||
finished_at=finished,
|
||||
duration_ms=_duration(started, finished),
|
||||
error_code=type(exc).__name__,
|
||||
error_message=str(exc) or "任务执行失败",
|
||||
error_message=_exception_message(exc),
|
||||
)
|
||||
raise
|
||||
finished = datetime.now(SHANGHAI)
|
||||
@@ -120,3 +120,10 @@ class JobService:
|
||||
|
||||
def _duration(started: datetime, finished: datetime) -> int:
|
||||
return max(0, round((finished - started).total_seconds() * 1000))
|
||||
|
||||
|
||||
def _exception_message(error: Exception) -> str:
|
||||
message = getattr(error, "message", None)
|
||||
if isinstance(message, str) and message.strip():
|
||||
return message.strip()
|
||||
return str(error).strip() or "任务执行失败"
|
||||
|
||||
Reference in New Issue
Block a user