feat: 正式池断联设备自动重连——①扫描线程每轮顺带对断联的网络设备 adb_connect_light(幂等,连上即恢复,无需人工;此前只有启动时预连接一次,断联后不会自己回来);②断联设备不删不进待连接池(pending 语义=未授权新设备),GET discovery 返回 pool_offline(serial/型号/备注);③POST /api/devices/discovery/reconnect 手动立即重连;④发现面板加「设备池断联设备」区块(自动重连中 + 立即重连按钮)
This commit is contained in:
+35
-1
@@ -118,14 +118,16 @@ def api_devices_pool_refresh_models():
|
||||
@bp.route("/api/devices/discovery", methods=["GET"])
|
||||
@perm_required(PERM_DEVICES)
|
||||
def api_devices_discovery():
|
||||
"""发现状态 + 待连接列表(前端 10s 轮询一次请求)。"""
|
||||
"""发现状态 + 待连接列表 + 正式池断联设备(前端 10s 轮询一次请求)。"""
|
||||
try:
|
||||
status = device_discovery.get_status()
|
||||
pending = device_discovery.list_pending()
|
||||
pool_offline = device_discovery.list_pool_offline()
|
||||
except Exception as e:
|
||||
_log.warning(f"discovery 状态获取失败: {e}")
|
||||
return jsonify({"ok": False, "error": str(e)[:120]}), 503
|
||||
status["pending"] = pending
|
||||
status["pool_offline"] = pool_offline
|
||||
return jsonify({"ok": True, **status})
|
||||
|
||||
|
||||
@@ -182,6 +184,38 @@ def api_devices_discovery_ignore():
|
||||
return jsonify({"ok": True, "msg": msg})
|
||||
|
||||
|
||||
@bp.route("/api/devices/discovery/reconnect", methods=["POST"])
|
||||
@perm_required(PERM_DEVICES)
|
||||
def api_devices_discovery_reconnect():
|
||||
"""手动立即重连正式池断联设备(后台 adb connect + 采型号)。
|
||||
|
||||
日常无需手动——发现线程每轮(默认 60s)自动重连断联设备;
|
||||
本端点用于不想等下一轮扫描时立即拉起。
|
||||
"""
|
||||
serial = (request.json or {}).get("serial", "").strip()
|
||||
if not serial:
|
||||
return jsonify({"ok": False, "error": "缺少 serial"}), 400
|
||||
from core import device_pool
|
||||
if serial not in device_pool.list_configured():
|
||||
return jsonify({"ok": False, "error": "设备不在设备池中"}), 404
|
||||
|
||||
def _reconnect():
|
||||
try:
|
||||
if ":" in serial:
|
||||
adb_connect(serial)
|
||||
# 无论是否连上,采一次型号(模型失败静默)
|
||||
try:
|
||||
device_pool.refresh_model(serial)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
_log.warning(f"手动重连 {serial} 异常: {e}")
|
||||
|
||||
threading.Thread(target=_reconnect, daemon=True).start()
|
||||
_log.info(f"设备池管理: 手动重连 {serial}")
|
||||
return jsonify({"ok": True, "msg": "重连已启动(约 5-15 秒生效)"})
|
||||
|
||||
|
||||
@bp.route("/api/devices/discovery/settings", methods=["POST"])
|
||||
@perm_required(PERM_DEVICES)
|
||||
def api_devices_discovery_settings():
|
||||
|
||||
Reference in New Issue
Block a user