From ac7be6ee0292033eaaf1635c324aea9e8d27d77c Mon Sep 17 00:00:00 2001 From: wangqifan Date: Fri, 24 Oct 2025 14:47:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0MAX=5FONLINE=E7=AD=9B?= =?UTF-8?q?=E9=80=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/.env | 4 +++- app/config.py | 1 + app/rotation_service.py | 15 +++++++++------ line_status.json | 10 ++++++++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/.env b/app/.env index 443b8ae..c408cc8 100644 --- a/app/.env +++ b/app/.env @@ -17,4 +17,6 @@ REDIS_URL=redis://127.0.0.1:6379/5 LOG_LEVEL=INFO # 端口数==条数 从172.30.168.2开始 -PORT_NUM=10 \ No newline at end of file +PORT_NUM=10 + +MAX_ONLINE=10000 \ No newline at end of file diff --git a/app/config.py b/app/config.py index 7f00586..fa5465a 100644 --- a/app/config.py +++ b/app/config.py @@ -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() diff --git a/app/rotation_service.py b/app/rotation_service.py index eea06e5..24096f4 100644 --- a/app/rotation_service.py +++ b/app/rotation_service.py @@ -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 diff --git a/line_status.json b/line_status.json index 8edd616..cdd697e 100644 --- a/line_status.json +++ b/line_status.json @@ -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" } } \ No newline at end of file