Files
android-fleet-godhead/proxy_qualify_loop.py

48 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Qualify loop: runs the IG/Google gate on every unqualified healthy proxy in the
bank, tagging ig_status. Eligible proxies are the only ones assigned to devices."""
import json
import sqlite3
import subprocess
import time
DB = "/opt/android-fleet/fleet.db"
def main():
con = sqlite3.connect(DB)
con.row_factory = sqlite3.Row
# ensure column
cols = [r[1] for r in con.execute("PRAGMA table_info(proxies)").fetchall()]
if "ig_status" not in cols:
con.execute("ALTER TABLE proxies ADD COLUMN ig_status TEXT DEFAULT 'unqualified'")
con.commit()
rows = con.execute("SELECT * FROM proxies WHERE health='healthy' AND ig_status='unqualified'").fetchall()
con.close()
if not rows:
return
# qualify via the CLI (bank mode would re-check all; we drive one by one)
for r in rows:
spec = f"{r['host']}:{r['port']}:{r['proto']}"
try:
out = subprocess.run(["python3", "/opt/android-fleet/proxy_qualify.py", spec],
capture_output=True, text=True, timeout=90).stdout
for line in out.splitlines():
if line.startswith("{"):
d = json.loads(line)
con = sqlite3.connect(DB)
con.execute("UPDATE proxies SET ig_status=? WHERE host=? AND port=?",
(d["verdict"], r["host"], r["port"]))
con.commit()
con.close()
print(f"{spec}: {d['verdict']} (ig={d.get('ig')}, google={d.get('google')})", flush=True)
except Exception as e:
print(f"{spec}: qualify err {e}", flush=True)
if __name__ == "__main__":
while True:
try:
main()
except Exception as e:
print("qualify loop err:", e, flush=True)
time.sleep(600)