添加MAX_ONLINE筛选功能

This commit is contained in:
wangqifan 2025-10-24 14:47:24 +08:00
parent cc6ef7f86f
commit ac7be6ee02
4 changed files with 23 additions and 7 deletions

View File

@ -18,3 +18,5 @@ LOG_LEVEL=INFO
# 端口数==条数 从172.30.168.2开始
PORT_NUM=10
MAX_ONLINE=10000

View File

@ -16,6 +16,7 @@ class Settings(BaseModel):
redis_url: str = os.getenv("REDIS_URL", "redis://localhost:6379/0")
log_level: str = os.getenv("LOG_LEVEL", "INFO")
port_num: int = int(os.getenv("PORT_NUM", 3))
max_online: int = int(os.getenv("MAX_ONLINE", 3))
settings = Settings()

View File

@ -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)
"""
for d in devices.get('edges'):
ip, edge_id = _extract_device_ip_and_id(d)
if not ip:
# 没有可识别的IP跳过此设备
continue
if not kv.is_ip_used_today(ip):
return ip, edge_id
# print(settings.max_online)
# print(d)
if d['online'] < settings.max_online:
ip, edge_id = _extract_device_ip_and_id(d)
if not ip:
# 没有可识别的IP跳过此设备
continue
if not kv.is_ip_used_today(ip):
return ip, edge_id
return None, None

View File

@ -28,5 +28,15 @@
"geo_location": "bc41d34110c2989b29f7521133d605e7a8aa6e9edb488217c5c0d087603a753c",
"rotate_count": 2,
"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"
}
}