Stage 07.4.4.1.14 — Execution refactoring and runtime semantics
This commit is contained in:
@@ -9,6 +9,8 @@ class EventBus:
|
||||
_version: int = 0
|
||||
_last_event_type: str | None = None
|
||||
_last_payload: dict[str, Any] = {}
|
||||
_events: list[tuple[int, str, dict[str, Any]]] = []
|
||||
_max_events: int = 100
|
||||
|
||||
# зафиксировать важное событие системы
|
||||
@classmethod
|
||||
@@ -17,6 +19,17 @@ class EventBus:
|
||||
cls._last_event_type = event_type
|
||||
cls._last_payload = payload or {}
|
||||
|
||||
cls._events.append(
|
||||
(
|
||||
cls._version,
|
||||
event_type,
|
||||
dict(cls._last_payload),
|
||||
)
|
||||
)
|
||||
|
||||
if len(cls._events) > cls._max_events:
|
||||
cls._events = cls._events[-cls._max_events:]
|
||||
|
||||
# текущая версия событий
|
||||
@classmethod
|
||||
def version(cls) -> int:
|
||||
@@ -25,4 +38,13 @@ class EventBus:
|
||||
# последнее событие
|
||||
@classmethod
|
||||
def last_event(cls) -> tuple[str | None, dict[str, Any]]:
|
||||
return cls._last_event_type, dict(cls._last_payload)
|
||||
return cls._last_event_type, dict(cls._last_payload)
|
||||
|
||||
# события после указанной версии
|
||||
@classmethod
|
||||
def events_after(cls, version: int) -> list[tuple[int, str, dict[str, Any]]]:
|
||||
return [
|
||||
(event_version, event_type, dict(payload))
|
||||
for event_version, event_type, payload in cls._events
|
||||
if event_version > version
|
||||
]
|
||||
Reference in New Issue
Block a user