proxyfly engine v2: 3-source harvest, stratified testing, 2-strike health, transparent incl, latency cap

This commit is contained in:
drjones
2026-08-13 17:15:43 -07:00
parent 67c8579db9
commit 38087a74c1
2 changed files with 106 additions and 41 deletions

29
app.py
View File

@@ -99,7 +99,8 @@ def init_db():
status TEXT, session_file TEXT, created REAL)""")
# proxy schema extensions (proxyfly integration)
for col, ddl in [("clean", "INTEGER DEFAULT 0"), ("country", "TEXT"),
("egress_ip", "TEXT"), ("source", "TEXT")]:
("egress_ip", "TEXT"), ("source", "TEXT"),
("fail_count", "INTEGER DEFAULT 0")]:
try:
con.execute(f"ALTER TABLE proxies ADD COLUMN {col} {ddl}")
except sqlite3.OperationalError:
@@ -379,8 +380,15 @@ def proxy_loop():
con = db()
for p in proxies:
health, lat, pub = results.get(p["id"], ("dead", None, None))
con.execute("UPDATE proxies SET health=?, latency_ms=?, last_check=? WHERE id=?",
(health, lat, time.time(), p["id"]))
if health == "healthy":
con.execute("UPDATE proxies SET health='healthy', latency_ms=?, last_check=?, fail_count=0 WHERE id=?",
(lat, time.time(), p["id"]))
else:
# 2-strike rule: free proxies flake; only die after consecutive failures
fc = (p["fail_count"] or 0) + 1
con.execute("UPDATE proxies SET fail_count=?, last_check=? WHERE id=?", (fc, time.time(), p["id"]))
if fc >= 2:
con.execute("UPDATE proxies SET health='dead' WHERE id=?", (p["id"],))
# auto-assign: prefer verified-clean, fall back to any healthy
if health == "healthy" and not p["assigned_mac"]:
devices = con.execute(
@@ -562,7 +570,20 @@ def spawn_worker(job_id, count, prefix):
{"newid": vmid, "name": name, "full": 0})
if r.get("data") is None and r.get("error"):
raise Exception(f"clone failed: {r.get('error')}")
pve("PUT", f"/nodes/pve/qemu/{vmid}/config", {"args": args, "memory": 3072, "cores": 2})
time.sleep(2)
cfg = {"args": args, "memory": 3072, "cores": 2}
applied = False
for _attempt in range(3):
pve("PUT", f"/nodes/pve/qemu/{vmid}/config", cfg)
time.sleep(2)
got = pve("GET", f"/nodes/pve/qemu/{vmid}/config")
cur = (got.get("data") or {}).get("args", "")
if f"59{display:02d}" in cur:
applied = True
break
time.sleep(3)
if not applied:
raise Exception(f"args did not apply for vmid {vmid}")
pve("POST", f"/nodes/pve/qemu/{vmid}/status/start", {})
vmids.append(vmid)
log("SPAWN", f"spawned {name} (vmid {vmid}, display {display})")