improved logging
This commit is contained in:
@@ -37,16 +37,19 @@ class RingBroadcaster:
|
||||
def register(self, queue: asyncio.Queue[dict]) -> None:
|
||||
"""Add a client queue to receive subsequent frames and status."""
|
||||
self._clients.add(queue)
|
||||
logger.debug("Registered web client queue (clients=%d)", len(self._clients))
|
||||
|
||||
def unregister(self, queue: asyncio.Queue[dict]) -> None:
|
||||
"""Remove a client queue; safe to call more than once."""
|
||||
self._clients.discard(queue)
|
||||
logger.debug("Unregistered web client queue (clients=%d)", len(self._clients))
|
||||
|
||||
def start(self) -> None:
|
||||
"""Launch the single polling task (idempotent)."""
|
||||
if self._task is None or self._task.done():
|
||||
self._task = asyncio.create_task(self._run(), name="ring-broadcaster")
|
||||
self._task.add_done_callback(self._on_task_done)
|
||||
logger.info("Ring broadcaster started")
|
||||
|
||||
@staticmethod
|
||||
def _on_task_done(task: "asyncio.Task[None]") -> None:
|
||||
@@ -62,6 +65,7 @@ class RingBroadcaster:
|
||||
with contextlib.suppress(asyncio.CancelledError):
|
||||
await self._task
|
||||
self._task = None
|
||||
logger.info("Ring broadcaster stopped")
|
||||
|
||||
def _publish(self, message: dict) -> None:
|
||||
"""Push a message to every client, dropping the oldest on a full queue."""
|
||||
|
||||
Reference in New Issue
Block a user