feat(recipes): add recipe rematch WebSocket progress channel

This commit is contained in:
Will Miao
2026-08-09 11:30:46 +08:00
parent 64da845a58
commit b2a1307d23
2 changed files with 115 additions and 0 deletions

View File

@@ -22,6 +22,8 @@ class WebSocketManager:
self._auto_organize_progress: Optional[Dict[str, Any]] = None
# Add recipe repair progress tracking
self._recipe_repair_progress: Optional[Dict[str, Any]] = None
# Add recipe rematch progress tracking
self._recipe_rematch_progress: Optional[Dict[str, Any]] = None
self._auto_organize_lock = asyncio.Lock()
async def handle_connection(self, request: web.Request) -> web.WebSocketResponse:
@@ -223,6 +225,30 @@ class WebSocketManager:
status = self._recipe_repair_progress.get('status')
return status in ['started', 'processing']
async def broadcast_recipe_rematch_progress(self, data: Dict[str, Any]):
"""Broadcast recipe rematch progress to connected clients"""
# Store progress data in memory
self._recipe_rematch_progress = data
# Broadcast via WebSocket
await self.broadcast(data)
def get_recipe_rematch_progress(self) -> Optional[Dict[str, Any]]:
"""Get current recipe rematch progress"""
return self._recipe_rematch_progress
def cleanup_recipe_rematch_progress(self):
"""Clear recipe rematch progress data if it is in a finished state"""
if self._recipe_rematch_progress and self._recipe_rematch_progress.get('status') in ['completed', 'cancelled', 'error']:
self._recipe_rematch_progress = None
def is_recipe_rematch_running(self) -> bool:
"""Check if recipe rematch is currently running"""
if not self._recipe_rematch_progress:
return False
status = self._recipe_rematch_progress.get('status')
return status in ['started', 'processing']
def is_auto_organize_running(self) -> bool:
"""Check if auto-organize is currently running"""
if not self._auto_organize_progress: