fix: 注销后关掉学习连接,目标为零不再显示成零比零
This commit is contained in:
@@ -49,6 +49,34 @@ def unregister(employee_id: str, ws: WebSocket) -> None:
|
||||
_last_flush.pop(key, None)
|
||||
|
||||
|
||||
def close_account(employee_id: str) -> None:
|
||||
"""注销或删除后关掉这个账号已经打开的学习状态连接。"""
|
||||
key = (employee_id or "").strip()
|
||||
if not key:
|
||||
return
|
||||
loop = _loop
|
||||
if loop is None or not loop.is_running():
|
||||
_drop_account(key)
|
||||
return
|
||||
loop.call_soon_threadsafe(_drop_account, key)
|
||||
|
||||
|
||||
def _drop_account(key: str) -> None:
|
||||
handle = _pending.pop(key, None)
|
||||
if handle is not None:
|
||||
handle.cancel()
|
||||
_dirty.discard(key)
|
||||
_urgent.discard(key)
|
||||
_inflight.discard(key)
|
||||
_last_flush.pop(key, None)
|
||||
sockets = list(_clients.pop(key, ()))
|
||||
for ws in sockets:
|
||||
try:
|
||||
asyncio.get_running_loop().create_task(ws.close(code=4401))
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
|
||||
def notify(employee_id: str | None = None, urgent: bool = False) -> None:
|
||||
loop = _loop
|
||||
if loop is None or not loop.is_running():
|
||||
|
||||
Reference in New Issue
Block a user