7a1329958d
- fix(render): ffmpeg overlay=0:0 -> overlay=0:0:shortest=1 to prevent hang on finite PNG sequences - feat(ws): add core/websocket.py ConnectionManager + Redis Pub/Sub subscriber loop - feat(ws): add /api/ws WebSocket endpoint with JWT query-param auth in main.py - feat(ws): emit render_complete/failed + cad_processing_complete events from step_tasks.py - feat(ws): emit order_status_change events from orders router - feat(ws): add beat_tasks.py broadcast_queue_status task (every 10s via Redis __broadcast__) - feat(frontend): add useWebSocket hook with auto-reconnect (exponential backoff, 25s ping) - feat(frontend): add WebSocketContext + WebSocketProvider wrapping App - refactor(frontend): remove polling from WorkerActivity (was 5s/3s) + OrderDetail (was 5s) - refactor(frontend): reduce polling in Layout (8s->60s) + NotificationCenter (15s->60s) - docs: add ffmpeg shortest=1 + WebSocket JWT auth learnings to LEARNINGS.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
"""Celery Beat periodic tasks."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import logging
|
|
|
|
from celery import shared_task
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@shared_task(name="app.tasks.beat_tasks.broadcast_queue_status", queue="step_processing")
|
|
def broadcast_queue_status() -> None:
|
|
"""Broadcast current queue depths to all WebSocket clients every 10s.
|
|
|
|
Publishes to the Redis '__broadcast__' channel which the WebSocket
|
|
subscriber in the FastAPI process forwards to all connected clients.
|
|
"""
|
|
try:
|
|
import redis as sync_redis
|
|
from app.config import settings
|
|
|
|
r = sync_redis.from_url(settings.redis_url, decode_responses=True)
|
|
depths = {
|
|
"step_processing": r.llen("step_processing"),
|
|
"thumbnail_rendering": r.llen("thumbnail_rendering"),
|
|
}
|
|
event = {"type": "queue_update", "depths": depths}
|
|
r.publish("__broadcast__", json.dumps(event))
|
|
r.close()
|
|
logger.debug("Broadcast queue_update: %s", depths)
|
|
except Exception as exc:
|
|
logger.warning("broadcast_queue_status failed: %s", exc)
|