fix(triggers): rename coerce helper to _store_int

Match the cron store-load naming and cover null attempts on deliveries.
This commit is contained in:
santhreal
2026-07-19 15:46:00 +08:00
committed by chengyongru
parent cf96c4d5e9
commit c2071594cf
2 changed files with 15 additions and 9 deletions
+6 -6
View File
@@ -11,7 +11,7 @@ from nanobot.utils.dict_keys import get_camel_snake as _get
TriggerStatus = Literal["ok", "error"]
def _ms_int(value: Any, default: int = 0) -> int:
def _store_int(value: Any, default: int = 0) -> int:
"""Coerce JSON numerics to int; treat null/blank like a missing key."""
if value is None or value == "":
return default
@@ -29,7 +29,7 @@ class TriggerRunRecord:
@classmethod
def from_dict(cls, data: dict[str, Any]) -> "TriggerRunRecord":
return cls(
run_at_ms=_ms_int(_get(data, "runAtMs", "run_at_ms", 0)),
run_at_ms=_store_int(_get(data, "runAtMs", "run_at_ms", 0)),
status=str(data.get("status") or "error"), # type: ignore[arg-type]
error=data.get("error"),
)
@@ -77,8 +77,8 @@ class LocalTrigger:
session_key=str(_get(data, "sessionKey", "session_key", "")),
sender_id=str(_get(data, "senderId", "sender_id", "trigger") or "trigger"),
origin_metadata=dict(_get(data, "originMetadata", "origin_metadata", {}) or {}),
created_at_ms=_ms_int(_get(data, "createdAtMs", "created_at_ms", 0)),
updated_at_ms=_ms_int(_get(data, "updatedAtMs", "updated_at_ms", 0)),
created_at_ms=_store_int(_get(data, "createdAtMs", "created_at_ms", 0)),
updated_at_ms=_store_int(_get(data, "updatedAtMs", "updated_at_ms", 0)),
last_run_at_ms=_get(data, "lastRunAtMs", "last_run_at_ms"),
last_status=_get(data, "lastStatus", "last_status"), # type: ignore[arg-type]
last_error=_get(data, "lastError", "last_error"),
@@ -127,8 +127,8 @@ class TriggerDelivery:
id=str(data["id"]),
trigger_id=str(_get(data, "triggerId", "trigger_id", "")),
content=str(data.get("content") or ""),
created_at_ms=_ms_int(_get(data, "createdAtMs", "created_at_ms", 0)),
attempts=_ms_int(data.get("attempts", 0)),
created_at_ms=_store_int(_get(data, "createdAtMs", "created_at_ms", 0)),
attempts=_store_int(data.get("attempts", 0)),
last_error=data.get("lastError") or data.get("last_error"),
path=path,
)