添加MAX_ONLINE筛选功能
This commit is contained in:
parent
cc6ef7f86f
commit
ac7be6ee02
4
app/.env
4
app/.env
@ -17,4 +17,6 @@ REDIS_URL=redis://127.0.0.1:6379/5
|
|||||||
LOG_LEVEL=INFO
|
LOG_LEVEL=INFO
|
||||||
|
|
||||||
# 端口数==条数 从172.30.168.2开始
|
# 端口数==条数 从172.30.168.2开始
|
||||||
PORT_NUM=10
|
PORT_NUM=10
|
||||||
|
|
||||||
|
MAX_ONLINE=10000
|
||||||
@ -16,6 +16,7 @@ class Settings(BaseModel):
|
|||||||
redis_url: str = os.getenv("REDIS_URL", "redis://localhost:6379/0")
|
redis_url: str = os.getenv("REDIS_URL", "redis://localhost:6379/0")
|
||||||
log_level: str = os.getenv("LOG_LEVEL", "INFO")
|
log_level: str = os.getenv("LOG_LEVEL", "INFO")
|
||||||
port_num: int = int(os.getenv("PORT_NUM", 3))
|
port_num: int = int(os.getenv("PORT_NUM", 3))
|
||||||
|
max_online: int = int(os.getenv("MAX_ONLINE", 3))
|
||||||
|
|
||||||
|
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
|||||||
@ -56,12 +56,15 @@ def select_unused_ip(devices: List[Dict[str, Any]]) -> Tuple[Optional[str], Opti
|
|||||||
Tuple[Optional[str], Optional[str]]: (IP地址, 边缘设备ID),如果没找到则返回(None, None)
|
Tuple[Optional[str], Optional[str]]: (IP地址, 边缘设备ID),如果没找到则返回(None, None)
|
||||||
"""
|
"""
|
||||||
for d in devices.get('edges'):
|
for d in devices.get('edges'):
|
||||||
ip, edge_id = _extract_device_ip_and_id(d)
|
# print(settings.max_online)
|
||||||
if not ip:
|
# print(d)
|
||||||
# 没有可识别的IP,跳过此设备
|
if d['online'] < settings.max_online:
|
||||||
continue
|
ip, edge_id = _extract_device_ip_and_id(d)
|
||||||
if not kv.is_ip_used_today(ip):
|
if not ip:
|
||||||
return ip, edge_id
|
# 没有可识别的IP,跳过此设备
|
||||||
|
continue
|
||||||
|
if not kv.is_ip_used_today(ip):
|
||||||
|
return ip, edge_id
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -28,5 +28,15 @@
|
|||||||
"geo_location": "bc41d34110c2989b29f7521133d605e7a8aa6e9edb488217c5c0d087603a753c",
|
"geo_location": "bc41d34110c2989b29f7521133d605e7a8aa6e9edb488217c5c0d087603a753c",
|
||||||
"rotate_count": 2,
|
"rotate_count": 2,
|
||||||
"last_update_time": "2025-10-22T14:34:16.436191"
|
"last_update_time": "2025-10-22T14:34:16.436191"
|
||||||
|
},
|
||||||
|
"6": {
|
||||||
|
"id": 6,
|
||||||
|
"current_ip": "120.239.76.220",
|
||||||
|
"last_rotate_time": "2025-10-24T14:42:24.742464",
|
||||||
|
"status": "active",
|
||||||
|
"edge_device": "DCD87C5682D8",
|
||||||
|
"geo_location": "ef26cdf15454e2aaba125512dcb6b509f0a9c02e0807ac13d4b77cbff52fe05d",
|
||||||
|
"rotate_count": 2,
|
||||||
|
"last_update_time": "2025-10-24T14:42:24.754469"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user