Event¶
event
¶
Module defining the base Event class for events.
Event
¶
Bases: Message[RawEventType]
Base class for all events.
Events represent something significant that happened in the system.
They are immutable facts about the past that other parts of the system can react to.
Events are named in past tense (e.g., OrderCreated, CustomerRegistered,
PaymentProcessed).
Example
class OrderCreatedPayload:
def __init__(self, order_id: str, customer_id: str, total: float) -> None:
self.order_id = order_id
self.customer_id = customer_id
self.total = total
class OrderCreated(Event[OrderCreatedPayload]):
def __init__(self, order_id: str, customer_id: str, total: float):
super().__init__()
self._order_id = order_id
self._customer_id = customer_id
self._total = total
@property
def _payload(self) -> OrderCreatedPayload:
return OrderCreatedPayload(
order_id=self._order_id,
customer_id=self._customer_id,
total=self._total,
)
@classmethod
def from_payload_fields(
cls, data: OrderCreatedPayload, metadata: MessageMetadata
) -> "OrderCreated":
return cls(
order_id=data.order_id,
customer_id=data.customer_id,
total=data.total,
)
@property
def value(self) -> OrderCreatedPayload:
return self._payload
Source code in src/forging_blocks/domain/messages/event.py
occurred_at: datetime
property
¶
Get the timestamp when this event occurred (UTC timezone).