forked from erp-dev/erp
added image_name to PlateOrder model
This commit is contained in:
@@ -82,6 +82,43 @@ def cleanup_all_connections():
|
||||
logger.info("所有SSE连接已清理")
|
||||
|
||||
|
||||
def shutdown_merchant_connections(merchant_id):
|
||||
"""
|
||||
关闭指定商户的所有连接
|
||||
|
||||
参数:
|
||||
- merchant_id: 商户ID
|
||||
|
||||
返回:
|
||||
- int: 关闭的连接数
|
||||
"""
|
||||
if merchant_id not in _connections:
|
||||
return 0
|
||||
|
||||
connections = _connections[merchant_id]
|
||||
count = len(connections)
|
||||
|
||||
# 向每个连接发送关闭信号
|
||||
for conn_queue in list(connections):
|
||||
try:
|
||||
conn_queue.put_nowait({
|
||||
'type': 'server_shutdown',
|
||||
'message': 'Server shutting down your connections, please reconnect later'
|
||||
})
|
||||
except queue.Full:
|
||||
# 队列满了,跳过
|
||||
pass
|
||||
except Exception:
|
||||
# 其他异常,也跳过
|
||||
pass
|
||||
|
||||
# 删除所有连接
|
||||
del _connections[merchant_id]
|
||||
|
||||
logger.info(f"关闭商户 {merchant_id} 的 {count} 个 SSE 连接")
|
||||
return count
|
||||
|
||||
|
||||
def push_sse_event_to_all(event_data: dict):
|
||||
"""
|
||||
向所有连接的客户端广播一个 SSE 事件(同步队列版本)
|
||||
|
||||
Reference in New Issue
Block a user