forked from Rockachopa/Timmy-time-dashboard
feat: code quality audit + autoresearch integration + infra hardening (#150)
This commit is contained in:
committed by
GitHub
parent
fd0ede0d51
commit
ae3bb1cc21
@@ -22,6 +22,7 @@ logger = logging.getLogger(__name__)
|
||||
@dataclass
|
||||
class WSEvent:
|
||||
"""A WebSocket event to broadcast to connected clients."""
|
||||
|
||||
event: str
|
||||
data: dict
|
||||
timestamp: str
|
||||
@@ -93,28 +94,42 @@ class WebSocketManager:
|
||||
await self.broadcast("agent_left", {"agent_id": agent_id, "name": name})
|
||||
|
||||
async def broadcast_task_posted(self, task_id: str, description: str) -> None:
|
||||
await self.broadcast("task_posted", {
|
||||
"task_id": task_id, "description": description,
|
||||
})
|
||||
await self.broadcast(
|
||||
"task_posted",
|
||||
{
|
||||
"task_id": task_id,
|
||||
"description": description,
|
||||
},
|
||||
)
|
||||
|
||||
async def broadcast_bid_submitted(
|
||||
self, task_id: str, agent_id: str, bid_sats: int
|
||||
) -> None:
|
||||
await self.broadcast("bid_submitted", {
|
||||
"task_id": task_id, "agent_id": agent_id, "bid_sats": bid_sats,
|
||||
})
|
||||
async def broadcast_bid_submitted(self, task_id: str, agent_id: str, bid_sats: int) -> None:
|
||||
await self.broadcast(
|
||||
"bid_submitted",
|
||||
{
|
||||
"task_id": task_id,
|
||||
"agent_id": agent_id,
|
||||
"bid_sats": bid_sats,
|
||||
},
|
||||
)
|
||||
|
||||
async def broadcast_task_assigned(self, task_id: str, agent_id: str) -> None:
|
||||
await self.broadcast("task_assigned", {
|
||||
"task_id": task_id, "agent_id": agent_id,
|
||||
})
|
||||
await self.broadcast(
|
||||
"task_assigned",
|
||||
{
|
||||
"task_id": task_id,
|
||||
"agent_id": agent_id,
|
||||
},
|
||||
)
|
||||
|
||||
async def broadcast_task_completed(
|
||||
self, task_id: str, agent_id: str, result: str
|
||||
) -> None:
|
||||
await self.broadcast("task_completed", {
|
||||
"task_id": task_id, "agent_id": agent_id, "result": result[:200],
|
||||
})
|
||||
async def broadcast_task_completed(self, task_id: str, agent_id: str, result: str) -> None:
|
||||
await self.broadcast(
|
||||
"task_completed",
|
||||
{
|
||||
"task_id": task_id,
|
||||
"agent_id": agent_id,
|
||||
"result": result[:200],
|
||||
},
|
||||
)
|
||||
|
||||
@property
|
||||
def connection_count(self) -> int:
|
||||
@@ -122,28 +137,28 @@ class WebSocketManager:
|
||||
|
||||
async def broadcast_json(self, data: dict) -> int:
|
||||
"""Broadcast raw JSON data to all connected clients.
|
||||
|
||||
|
||||
Args:
|
||||
data: Dictionary to send as JSON
|
||||
|
||||
|
||||
Returns:
|
||||
Number of clients notified
|
||||
"""
|
||||
message = json.dumps(data)
|
||||
disconnected = []
|
||||
count = 0
|
||||
|
||||
|
||||
for ws in self._connections:
|
||||
try:
|
||||
await ws.send_text(message)
|
||||
count += 1
|
||||
except Exception:
|
||||
disconnected.append(ws)
|
||||
|
||||
|
||||
# Clean up dead connections
|
||||
for ws in disconnected:
|
||||
self.disconnect(ws)
|
||||
|
||||
|
||||
return count
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user