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:
2026-06-21 19:25:55 +09:00
co-authored by Claude Opus 4.8
parent b2165eac25
commit d4c5fcbba1
29 changed files with 1195 additions and 47 deletions
+26 -12
View File
@@ -44,6 +44,7 @@ from trex_core.adapters.portfolio import (
StubPortfolioRead,
)
from trex_core.adapters.portfolio.killswitch_store import PostgreSQLKillSwitchStore
from trex_core.application.alarm_emitter import AlarmEmitter
from trex_core.application.broker_port import BrokerPort
from trex_core.application.execution import ExecutionService
from trex_core.application.intents import IntentService
@@ -169,25 +170,42 @@ class Daemon:
# BAT-008: portfolio-hub read + snapshot store + durable pause + scheduler.
# (Created before the ledger writer so option-D write-back can target it.)
self.snapshot_store = SnapshotStore()
# BAT-010/011: per-slot watchdog (snapshot RPC writer, safety-sell reader).
self.watchdog = WatchdogStore()
self.pause_store = PostgreSQLPauseStore(config.dsn)
# BAT-012: day-scoped kill-switch exclusion store + service.
self.killswitch_store = PostgreSQLKillSwitchStore(config.dsn)
self.portfolio_read = _build_portfolio_read(config)
# Event publisher transport — one dedicated instance for the
# execution-loop thread (pika is not thread-safe).
self.event_publisher: MessagingTransport = _build_transport(config)
self._transports.append(self.event_publisher)
# dcy-033 / REQ-100: alarm emitter — shares the event_publisher transport
# (both run on the execution-loop thread; pika thread-safety rule satisfied).
# Created before services so all services receive the same emitter instance.
self.alarm_emitter = AlarmEmitter(self.event_publisher)
# Late-bind alarm callback into event_publisher for adapter-layer alarm codes
# (KD-1: publish_unavailable_after_reconnect / dlq_publish_failed).
if hasattr(self.event_publisher, "set_alarm_callback"):
self.event_publisher.set_alarm_callback(self.alarm_emitter.publish_alarm)
self.ledger_writer = LedgerWriter(
self.outbox, _build_ledger(config),
snapshot_store=self.snapshot_store, # dcy-018 / REQ-030: option D write-back
retry_base_sec=config.ledger_retry_base_sec,
retry_cap_sec=config.ledger_retry_cap_sec,
max_attempts=config.ledger_max_attempts,
alarm_emitter=self.alarm_emitter, # dcy-033 / REQ-100
)
# BAT-010/011: per-slot watchdog (snapshot RPC writer, safety-sell reader).
self.watchdog = WatchdogStore()
self.pause_store = PostgreSQLPauseStore(config.dsn)
# BAT-012: day-scoped kill-switch exclusion store + service.
self.killswitch_store = PostgreSQLKillSwitchStore(config.dsn)
self.kill_switch = KillSwitchService(
slot_repo=self.slot_repo,
slot_service=self.slot_service,
killswitch_store=self.killswitch_store,
instance_key=config.instance_key,
alarm_emitter=self.alarm_emitter, # dcy-033 / REQ-100
)
self.portfolio_read = _build_portfolio_read(config)
self.snapshot_scheduler = SnapshotScheduler(
read_port=self.portfolio_read,
store=self.snapshot_store,
@@ -199,19 +217,15 @@ class Daemon:
slot_repo=self.slot_repo,
slot_service=self.slot_service,
instance_key=config.instance_key,
alarm_emitter=self.alarm_emitter, # dcy-033 / REQ-100
)
# Event publisher transport — one dedicated instance for the
# execution-loop thread (pika is not thread-safe).
self.event_publisher: MessagingTransport = _build_transport(config)
self._transports.append(self.event_publisher)
self.execution = ExecutionService(
self.slot_service, self.slot_repo, self.broker,
ledger_outbox=self.outbox,
event_emitter=self._make_event_emitter(),
stale_pending_threshold_sec=config.pending_stale_threshold_sec,
instance_key=config.instance_key,
alarm_emitter=self.alarm_emitter, # dcy-033 / REQ-100
)
# BAT-011: safety-sell trigger service (forced_close / SL-TP / market-close).