feat: support dynamic daemon refill
This commit is contained in:
27
main.py
27
main.py
@@ -287,7 +287,7 @@ def _derive_register_cap(cfg: dict[str, Any], explicit_cap: int) -> int:
|
||||
if explicit_cap and explicit_cap > 0:
|
||||
return explicit_cap
|
||||
try:
|
||||
return max(1, int(cfg.get("auto_register_max_per_loop", 1) or 1))
|
||||
return max(0, int(cfg.get("auto_register_max_per_loop", 1) or 0))
|
||||
except (TypeError, ValueError):
|
||||
return 1
|
||||
|
||||
@@ -356,8 +356,11 @@ def handle_daemon(args: argparse.Namespace) -> dict[str, Any]:
|
||||
if unhealthy:
|
||||
names = ", ".join(item["name"] for item in unhealthy)
|
||||
deficit = _calculate_register_deficit(unhealthy)
|
||||
planned = max(1, min(register_cap, deficit or 1))
|
||||
print(f"[!] 号池不足,开始自动补号: {names},差值约 {deficit},本轮计划补 {planned} 个")
|
||||
planned = max(1, deficit or 1) if register_cap == 0 else max(1, min(register_cap, deficit or 1))
|
||||
if register_cap == 0:
|
||||
print(f"[!] 号池不足,开始自动补号: {names},差值约 {deficit},本轮按差值动态补 {planned} 个")
|
||||
else:
|
||||
print(f"[!] 号池不足,开始自动补号: {names},差值约 {deficit},本轮计划补 {planned} 个")
|
||||
for index in range(planned):
|
||||
print(f"[*] 自动补号进度: {index + 1}/{planned}")
|
||||
try:
|
||||
@@ -477,6 +480,20 @@ def _prompt_int(prompt: str, default: int) -> int:
|
||||
print("请输入整数。")
|
||||
|
||||
|
||||
def _prompt_non_negative_int(prompt: str, default: int) -> int:
|
||||
while True:
|
||||
value = _prompt_text(prompt, str(default)).strip()
|
||||
try:
|
||||
parsed = int(value)
|
||||
except ValueError:
|
||||
print("请输入大于等于 0 的整数。")
|
||||
continue
|
||||
if parsed < 0:
|
||||
print("请输入大于等于 0 的整数。")
|
||||
continue
|
||||
return parsed
|
||||
|
||||
|
||||
def _prompt_choice(prompt: str, options: list[str], default: str) -> str:
|
||||
option_text = "/".join(options)
|
||||
default_value = default if default in options else options[0]
|
||||
@@ -499,8 +516,8 @@ def handle_config_setup(args: argparse.Namespace) -> dict[str, Any]:
|
||||
|
||||
cfg["proxy"] = _prompt_text("1) 注册代理地址", str(cfg.get("proxy") or "http://127.0.0.1:17891"))
|
||||
cfg["auto_register"] = _prompt_bool("2) 池不足时自动注册", bool(cfg.get("auto_register", False)))
|
||||
cfg["auto_register_max_per_loop"] = _prompt_int(" 每轮最多自动补号数量", int(cfg.get("auto_register_max_per_loop", 1) or 1))
|
||||
print(" 提示: 这个值越大,补号越快,但也会更激进。一般先用 1 或 2。")
|
||||
cfg["auto_register_max_per_loop"] = _prompt_non_negative_int(" 每轮最多自动补号数量(0 表示按差值动态补齐)", int(cfg.get("auto_register_max_per_loop", 1) or 1))
|
||||
print(" 提示: 0 表示按差值动态补齐;值越大补号越快,也会更激进。一般先用 1、2 或 0。")
|
||||
cfg["db_enabled"] = _prompt_bool(" 是否启用 PostgreSQL 注册信息入库", bool(cfg.get("db_enabled", False)))
|
||||
if cfg["db_enabled"]:
|
||||
cfg["db_host"] = _prompt_text(" DB 主机", str(cfg.get("db_host") or "150.158.105.6"))
|
||||
|
||||
Reference in New Issue
Block a user