ciyidogan commited on
Commit
c84b451
·
verified ·
1 Parent(s): 8eda44f

Update event_bus.py

Browse files
Files changed (1) hide show
  1. event_bus.py +33 -3
event_bus.py CHANGED
@@ -64,11 +64,41 @@ class EventType(Enum):
64
  class Event:
65
  """Event data structure"""
66
  type: EventType
67
- session_id: str
68
  data: Dict[str, Any]
69
- timestamp: datetime = None
70
- priority: int = 0 # Higher priority = processed first
 
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  def __post_init__(self):
73
  if self.timestamp is None:
74
  self.timestamp = datetime.utcnow()
 
64
  class Event:
65
  """Event data structure"""
66
  type: EventType
 
67
  data: Dict[str, Any]
68
+ session_id: Optional[str] = None
69
+ timestamp: datetime = field(default_factory=datetime.utcnow)
70
+ priority: int = 0
71
 
72
+ def __lt__(self, other):
73
+ """Compare events by priority for PriorityQueue"""
74
+ if not isinstance(other, Event):
75
+ return NotImplemented
76
+ # Önce priority'ye göre karşılaştır
77
+ if self.priority != other.priority:
78
+ return self.priority < other.priority
79
+ # Priority eşitse timestamp'e göre karşılaştır
80
+ return self.timestamp < other.timestamp
81
+
82
+ def __eq__(self, other):
83
+ """Check event equality"""
84
+ if not isinstance(other, Event):
85
+ return NotImplemented
86
+ return (self.priority == other.priority and
87
+ self.timestamp == other.timestamp and
88
+ self.type == other.type)
89
+
90
+ def __le__(self, other):
91
+ """Less than or equal comparison"""
92
+ return self == other or self < other
93
+
94
+ def __gt__(self, other):
95
+ """Greater than comparison"""
96
+ return not self <= other
97
+
98
+ def __ge__(self, other):
99
+ """Greater than or equal comparison"""
100
+ return not self < other
101
+
102
  def __post_init__(self):
103
  if self.timestamp is None:
104
  self.timestamp = datetime.utcnow()