feat(alarm): trex-core 알람 emitter + trex.alerts exchange (dcy-033 BAT-049, Implemented)
AlarmEmitter(application, best-effort 비차단)+trex.alerts topic exchange 가산·격리+8 CRITICAL code 배선. 608 passed, opus QC PASS, 팀장 e2e(텔레그램 HTTP200) 통과. REQ-098~101 Implemented. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VHtM5Ws1HKCKQ4JGi6GRb5
This commit is contained in:
@@ -29,6 +29,21 @@ from typing import Any, Optional
|
||||
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _emit_reset_alarm(
|
||||
alarm_emitter: Optional[object],
|
||||
code: str,
|
||||
title: str,
|
||||
fields: dict | None = None,
|
||||
) -> None:
|
||||
"""Best-effort alarm from reset.py (transport may be None — dcy-033 / REQ-100 KD-2)."""
|
||||
if alarm_emitter is None:
|
||||
return
|
||||
try:
|
||||
alarm_emitter.publish_alarm(code, title, fields=fields) # type: ignore[union-attr]
|
||||
except Exception: # noqa: BLE001
|
||||
_log.debug("reset alarm emit failed (code=%s)", code, exc_info=True)
|
||||
|
||||
# slot-core tables owned by trex-core migrations (drop order irrelevant — no FKs).
|
||||
SLOT_CORE_TABLES: tuple[str, ...] = (
|
||||
"daily_slot",
|
||||
@@ -74,6 +89,7 @@ def run_reset(
|
||||
*,
|
||||
dry_run: bool = True,
|
||||
psycopg_module: Any = None,
|
||||
alarm_emitter: Optional[object] = None,
|
||||
) -> ResetReport:
|
||||
"""Wipe the slot-core tables and reapply migrations to the asset-centric schema.
|
||||
|
||||
@@ -106,7 +122,17 @@ def run_reset(
|
||||
# 010 sets the inactive CHECK, 011 drops the pool-model columns.
|
||||
from trex_core.adapters.persistence.migrate import apply_migrations
|
||||
|
||||
report.migrations_applied = apply_migrations(dsn, psycopg_module=psycopg_module)
|
||||
try:
|
||||
report.migrations_applied = apply_migrations(dsn, psycopg_module=psycopg_module)
|
||||
except Exception as mig_exc: # noqa: BLE001
|
||||
# dcy-033 / REQ-100: CRITICAL alarm — migration failed.
|
||||
_emit_reset_alarm(
|
||||
alarm_emitter,
|
||||
"migration_failed",
|
||||
f"마이그레이션 실패: {mig_exc.__class__.__name__}",
|
||||
fields={"error": str(mig_exc)},
|
||||
)
|
||||
raise
|
||||
|
||||
from trex_core.domain.slot import EXPECTED_SLOT_FIELDS
|
||||
|
||||
@@ -118,6 +144,14 @@ def run_reset(
|
||||
)
|
||||
cols = {r[0] for r in cur.fetchall()}
|
||||
report.schema_ok = cols == set(EXPECTED_SLOT_FIELDS)
|
||||
if not report.schema_ok:
|
||||
# dcy-033 / REQ-100: CRITICAL alarm — schema verification failed post-reset.
|
||||
_emit_reset_alarm(
|
||||
alarm_emitter,
|
||||
"schema_verification_failed",
|
||||
"리셋 후 schema 검증 실패: daily_slot 컬럼 불일치",
|
||||
fields={"expected": sorted(EXPECTED_SLOT_FIELDS), "actual": sorted(cols)},
|
||||
)
|
||||
return report
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user