2025-07-17 13:09:24 +02:00
|
|
|
"""
|
|
|
|
|
Event definitions for microservices communication
|
2025-07-17 19:03:11 +02:00
|
|
|
- Simple class-based approach to avoid dataclass issues
|
2025-07-17 13:09:24 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
from typing import Dict, Any, Optional
|
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
class BaseEvent:
|
|
|
|
|
"""Base event class"""
|
2025-07-17 19:03:11 +02:00
|
|
|
def __init__(self, service_name: str, data: Dict[str, Any], event_type: str = "", correlation_id: Optional[str] = None):
|
|
|
|
|
self.service_name = service_name
|
|
|
|
|
self.data = data
|
|
|
|
|
self.event_type = event_type
|
|
|
|
|
self.event_id = str(uuid.uuid4())
|
|
|
|
|
self.timestamp = datetime.utcnow()
|
|
|
|
|
self.correlation_id = correlation_id
|
2025-07-17 13:09:24 +02:00
|
|
|
|
|
|
|
|
# Training Events
|
|
|
|
|
class TrainingStartedEvent(BaseEvent):
|
2025-07-17 19:03:11 +02:00
|
|
|
def __init__(self, service_name: str, data: Dict[str, Any], correlation_id: Optional[str] = None):
|
|
|
|
|
super().__init__(
|
|
|
|
|
service_name=service_name,
|
|
|
|
|
data=data,
|
|
|
|
|
event_type="training.started",
|
|
|
|
|
correlation_id=correlation_id
|
|
|
|
|
)
|
2025-07-17 13:09:24 +02:00
|
|
|
|
|
|
|
|
class TrainingCompletedEvent(BaseEvent):
|
2025-07-17 19:03:11 +02:00
|
|
|
def __init__(self, service_name: str, data: Dict[str, Any], correlation_id: Optional[str] = None):
|
|
|
|
|
super().__init__(
|
|
|
|
|
service_name=service_name,
|
|
|
|
|
data=data,
|
|
|
|
|
event_type="training.completed",
|
|
|
|
|
correlation_id=correlation_id
|
|
|
|
|
)
|
2025-07-17 13:09:24 +02:00
|
|
|
|
|
|
|
|
class TrainingFailedEvent(BaseEvent):
|
2025-07-17 19:03:11 +02:00
|
|
|
def __init__(self, service_name: str, data: Dict[str, Any], correlation_id: Optional[str] = None):
|
|
|
|
|
super().__init__(
|
|
|
|
|
service_name=service_name,
|
|
|
|
|
data=data,
|
|
|
|
|
event_type="training.failed",
|
|
|
|
|
correlation_id=correlation_id
|
|
|
|
|
)
|
2025-07-17 13:09:24 +02:00
|
|
|
|
|
|
|
|
# Forecasting Events
|
|
|
|
|
class ForecastGeneratedEvent(BaseEvent):
|
2025-07-17 19:03:11 +02:00
|
|
|
def __init__(self, service_name: str, data: Dict[str, Any], correlation_id: Optional[str] = None):
|
|
|
|
|
super().__init__(
|
|
|
|
|
service_name=service_name,
|
|
|
|
|
data=data,
|
|
|
|
|
event_type="forecast.generated",
|
|
|
|
|
correlation_id=correlation_id
|
|
|
|
|
)
|
2025-07-17 13:09:24 +02:00
|
|
|
|
|
|
|
|
class ForecastRequestedEvent(BaseEvent):
|
2025-07-17 19:03:11 +02:00
|
|
|
def __init__(self, service_name: str, data: Dict[str, Any], correlation_id: Optional[str] = None):
|
|
|
|
|
super().__init__(
|
|
|
|
|
service_name=service_name,
|
|
|
|
|
data=data,
|
|
|
|
|
event_type="forecast.requested",
|
|
|
|
|
correlation_id=correlation_id
|
|
|
|
|
)
|
2025-07-17 13:09:24 +02:00
|
|
|
|
|
|
|
|
# User Events
|
|
|
|
|
class UserRegisteredEvent(BaseEvent):
|
2025-07-17 19:03:11 +02:00
|
|
|
def __init__(self, service_name: str, data: Dict[str, Any], correlation_id: Optional[str] = None):
|
|
|
|
|
super().__init__(
|
|
|
|
|
service_name=service_name,
|
|
|
|
|
data=data,
|
|
|
|
|
event_type="user.registered",
|
|
|
|
|
correlation_id=correlation_id
|
|
|
|
|
)
|
2025-07-17 13:09:24 +02:00
|
|
|
|
|
|
|
|
class UserLoginEvent(BaseEvent):
|
2025-07-17 19:03:11 +02:00
|
|
|
def __init__(self, service_name: str, data: Dict[str, Any], correlation_id: Optional[str] = None):
|
|
|
|
|
super().__init__(
|
|
|
|
|
service_name=service_name,
|
|
|
|
|
data=data,
|
|
|
|
|
event_type="user.login",
|
|
|
|
|
correlation_id=correlation_id
|
|
|
|
|
)
|
2025-07-17 13:09:24 +02:00
|
|
|
|
|
|
|
|
# Tenant Events
|
|
|
|
|
class TenantCreatedEvent(BaseEvent):
|
2025-07-17 19:03:11 +02:00
|
|
|
def __init__(self, service_name: str, data: Dict[str, Any], correlation_id: Optional[str] = None):
|
|
|
|
|
super().__init__(
|
|
|
|
|
service_name=service_name,
|
|
|
|
|
data=data,
|
|
|
|
|
event_type="tenant.created",
|
|
|
|
|
correlation_id=correlation_id
|
|
|
|
|
)
|
2025-07-17 13:09:24 +02:00
|
|
|
|
|
|
|
|
class TenantUpdatedEvent(BaseEvent):
|
2025-07-17 19:03:11 +02:00
|
|
|
def __init__(self, service_name: str, data: Dict[str, Any], correlation_id: Optional[str] = None):
|
|
|
|
|
super().__init__(
|
|
|
|
|
service_name=service_name,
|
|
|
|
|
data=data,
|
|
|
|
|
event_type="tenant.updated",
|
|
|
|
|
correlation_id=correlation_id
|
|
|
|
|
)
|
2025-07-17 13:09:24 +02:00
|
|
|
|
|
|
|
|
# Notification Events
|
|
|
|
|
class NotificationSentEvent(BaseEvent):
|
2025-07-17 19:03:11 +02:00
|
|
|
def __init__(self, service_name: str, data: Dict[str, Any], correlation_id: Optional[str] = None):
|
|
|
|
|
super().__init__(
|
|
|
|
|
service_name=service_name,
|
|
|
|
|
data=data,
|
|
|
|
|
event_type="notification.sent",
|
|
|
|
|
correlation_id=correlation_id
|
|
|
|
|
)
|
2025-07-17 13:09:24 +02:00
|
|
|
|
|
|
|
|
class NotificationFailedEvent(BaseEvent):
|
2025-07-17 19:03:11 +02:00
|
|
|
def __init__(self, service_name: str, data: Dict[str, Any], correlation_id: Optional[str] = None):
|
|
|
|
|
super().__init__(
|
|
|
|
|
service_name=service_name,
|
|
|
|
|
data=data,
|
|
|
|
|
event_type="notification.failed",
|
|
|
|
|
correlation_id=correlation_id
|
|
|
|
|
)
|