Fix bugs issues

This commit is contained in:
Urtzi Alfaro
2025-07-18 13:39:40 +02:00
parent a38e5e7c22
commit 57ac772c6c
4 changed files with 59 additions and 22 deletions

View File

@@ -3,7 +3,7 @@ Event definitions for microservices communication
- Simple class-based approach to avoid dataclass issues
"""
from datetime import datetime
from datetime import datetime, timezone
from typing import Dict, Any, Optional
import uuid
@@ -14,8 +14,19 @@ class BaseEvent:
self.data = data
self.event_type = event_type
self.event_id = str(uuid.uuid4())
self.timestamp = datetime.utcnow()
self.timestamp = datetime.now(timezone.utc)
self.correlation_id = correlation_id
def to_dict(self) -> Dict[str, Any]: # Add this method
"""Converts the event object to a dictionary for JSON serialization."""
return {
"service_name": self.service_name,
"data": self.data,
"event_type": self.event_type,
"event_id": self.event_id,
"timestamp": self.timestamp.isoformat(), # Convert datetime to ISO 8601 string
"correlation_id": self.correlation_id
}
# Training Events
class TrainingStartedEvent(BaseEvent):