Files
2125_GCE/runtime_executor/events.py
T

49 lines
1.0 KiB
Python
Raw Normal View History

2026-07-09 12:54:44 -04:00
import logging
from dataclasses import dataclass
from typing import List, Callable, Any
2026-07-09 12:54:44 -04:00
logger = logging.getLogger(__name__)
@dataclass
class SegmentStartEvent:
segment_id: str
timestamp: float
@dataclass
class SegmentEndEvent:
segment_id: str
duration: float
timestamp: float
@dataclass
class ExecutionErrorEvent:
segment_id: str
error_msg: str
timestamp: float
class RuntimeEventBus:
def __init__(self):
self._subscribers: List[Callable] = []
2026-07-09 12:54:44 -04:00
self._errors: List[Exception] = []
def subscribe(self, callback: Callable):
self._subscribers.append(callback)
def publish(self, event: Any):
for callback in self._subscribers:
try:
callback(event)
2026-07-09 12:54:44 -04:00
except Exception as e:
self._errors.append(e)
logger.warning(f"RuntimeEventBus handler error: {e}")
def get_errors(self) -> List[Exception]:
return self._errors.copy()
def clear_errors(self) -> None:
self._errors.clear()