Poll database for progress changes and send updates.
(websocket: WebSocket, project_name: str, project_dir: Path)
| 685 | manager = ConnectionManager() |
| 686 | |
| 687 | async def poll_progress(websocket: WebSocket, project_name: str, project_dir: Path): |
| 688 | """Poll database for progress changes and send updates.""" |
| 689 | count_passing_tests = _get_count_passing_tests() |
| 690 | last_passing = -1 |
| 691 | last_in_progress = -1 |
| 692 | last_total = -1 |
| 693 | |
| 694 | while True: |
| 695 | try: |
| 696 | passing, in_progress, total = count_passing_tests(project_dir) |
| 697 | |
| 698 | # Only send if changed |
| 699 | if passing != last_passing or in_progress != last_in_progress or total != last_total: |
| 700 | last_passing = passing |
| 701 | last_in_progress = in_progress |
| 702 | last_total = total |
| 703 | percentage = (passing / total * 100) if total > 0 else 0 |
| 704 | |
| 705 | await websocket.send_json({ |
| 706 | "type": "progress", |
| 707 | "passing": passing, |
| 708 | "in_progress": in_progress, |
| 709 | "total": total, |
| 710 | "percentage": round(percentage, 1), |
| 711 | }) |
| 712 | |
| 713 | await asyncio.sleep(2) # Poll every 2 seconds |
| 714 | except asyncio.CancelledError: |
| 715 | raise |
| 716 | except Exception as e: |
| 717 | logger.warning(f"Progress polling error: {e}") |
| 718 | break |
| 719 | |
| 720 | |
| 721 | async def project_websocket(websocket: WebSocket, project_name: str): |
no test coverage detected