fix(intents): isolate alarm context lookup and sanitize alarm failure logs
Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
co-authored by
genichin
parent
5dd3d57f86
commit
1ca9e60c98
@@ -17,6 +17,7 @@ where no broker connection exists. In that case publish_alarm() logs and skips.
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from trex_core.adapters.messaging.topology import alarm_routing_key
|
||||
@@ -84,15 +85,17 @@ class AlarmEmitter:
|
||||
try:
|
||||
self._transport.publish_alarm_event(routing_key, payload)
|
||||
return True
|
||||
except TransportUnavailableError as exc:
|
||||
except TransportUnavailableError:
|
||||
_log.error(
|
||||
"alarm publish skipped (transport unavailable): code=%s: %s",
|
||||
code, exc,
|
||||
"alarm publish skipped (transport unavailable): code=%s title=%s",
|
||||
code, title,
|
||||
)
|
||||
return False
|
||||
except Exception: # noqa: BLE001 — alarm must never crash the caller
|
||||
exc = sys.exc_info()[1]
|
||||
exc_name = type(exc).__name__ if exc is not None else "Exception"
|
||||
_log.error(
|
||||
"alarm publish failed: code=%s title=%s",
|
||||
code, title, exc_info=True,
|
||||
"alarm publish failed: code=%s title=%s error_type=%s",
|
||||
code, title, exc_name,
|
||||
)
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user