#!/usr/bin/env python3 # [ACE 1114] докорм пула acemusic.ai: добивает банк до TARGET и синкает на прод import json, os, re, subprocess, sys, time BASE = r"C:/Users/User/tmp/acemusic" BANK = os.path.join(BASE, "bank.jsonl") TARGET = int(os.environ.get("ACE_TARGET", "150")) BATCH = int(os.environ.get("ACE_BATCH", "15")) KEY = r"C:/Users/User/.ssh/id_ed25519" PROD = "root@2.27.98.196" def count_and_max(): n = 0; mx = 0; seen = set() if os.path.exists(BANK): for line in open(BANK, encoding="utf-8", errors="replace"): line = line.strip() if not line: continue try: r = json.loads(line) except Exception: continue n += 1 seen.add(r.get("email")) m = re.search(r"ace(\d+)@", r.get("email") or "") if m: mx = max(mx, int(m.group(1))) return n, mx n, mx = count_and_max() print("bank", n, "max_idx", mx, "target", TARGET, flush=True) if n >= TARGET: print("pool full, skip", flush=True) else: need = min(BATCH, TARGET - n) start = mx + 1 print("farming", need, "accounts from", start, flush=True) r = subprocess.run([sys.executable, "wave.py", str(start), str(need), "ace"], cwd=BASE, capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=1500) tail = (r.stdout or "")[-1500:] print(tail, flush=True) print("wave rc", r.returncode, flush=True) # синк банка на прод n2, _ = count_and_max() scp = subprocess.run(["scp", "-o", "StrictHostKeyChecking=no", "-i", KEY, BANK, PROD + ":/opt/ace-shim/bank.jsonl"], capture_output=True, text=True, timeout=180) print("scp rc", scp.returncode, (scp.stderr or "")[:200], flush=True) try: import urllib.request h = json.load(urllib.request.urlopen("http://2.27.98.196:48963/healthz", timeout=8)) print("pool: accounts=%s alive=%s credits=%s songs=%s" % (h.get("accounts"), h.get("alive"), h.get("credits_total"), h.get("songs_capacity")), flush=True) except Exception as e: print("health err", str(e)[:120], flush=True) print("bank_lines", n2, flush=True)