add refresh_balances/diag, tokens_guard (single UPDATE), priority notes; 70 accounts live
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Один UPDATE: дописывает модели DeepAI Code в tokens.model_limits всем живым токенам.
|
||||
|
||||
27 отдельных UPDATE не укладываются в таймаут (триггер аудита на каждой строке).
|
||||
python3 /opt/dpcode/tokens_guard.py [--quiet]
|
||||
"""
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
MODELS = [
|
||||
"glm-5.3-flash", "deepseek-v4.1-flash", "mimo-2.6-flash", "qwen-3.8-flash",
|
||||
"minimax-m3.1-flash", "muse-ember", "solar-mini-4", "gpt-6-luna",
|
||||
"mimo-2.6-pro", "glyph-cluster", "deepai-cyber",
|
||||
"claude-opus-5-5", "claude-sonnet-5-5", "claude-fable-5-2", "gpt-6.1-sol",
|
||||
"gpt-6.1-terra", "gpt-6-astra", "gemini-4-argon", "gemini-4-hydrogen",
|
||||
"gemini-4-carbon", "glm-5.3", "kimi-k3", "kimi-k3.1-pro", "minimax-m3",
|
||||
"muse-spark-1.3", "muse-wonder", "qwen-3.8-max-prime",
|
||||
]
|
||||
SQL_PATH = "/tmp/dpa_guard.sql"
|
||||
quiet = "--quiet" in sys.argv
|
||||
arr = "ARRAY[" + ",".join("'%s'" % m for m in MODELS) + "]"
|
||||
|
||||
|
||||
def sql():
|
||||
return (
|
||||
"SET statement_timeout = '240s';\n"
|
||||
"UPDATE tokens t SET model_limits = s.newlim FROM (\n"
|
||||
" SELECT id, array_to_string(ARRAY(\n"
|
||||
" SELECT DISTINCT e FROM unnest(string_to_array(coalesce(model_limits,''), ',') || "
|
||||
+ arr + ") AS e WHERE e <> ''\n"
|
||||
" ), ',') AS newlim FROM tokens WHERE status = 1\n"
|
||||
") s\n"
|
||||
"WHERE t.id = s.id AND coalesce(t.model_limits,'') <> s.newlim\n"
|
||||
" AND (','||coalesce(t.model_limits,'')||',') NOT LIKE '%,claude-opus-5-5,%';\n"
|
||||
"SELECT count(*) FROM tokens WHERE status=1 AND (','||coalesce(model_limits,'')||',') "
|
||||
"LIKE '%,claude-opus-5-5,%';\n"
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
open(SQL_PATH, "w", encoding="utf-8").write(sql())
|
||||
os.chmod(SQL_PATH, 0o644)
|
||||
r = subprocess.run(["su", "postgres", "-c",
|
||||
"psql -d newapi -At -v ON_ERROR_STOP=1 -f %s" % SQL_PATH],
|
||||
capture_output=True, text=True, cwd="/tmp")
|
||||
out = [x for x in (r.stdout or "").strip().splitlines() if x]
|
||||
err = (r.stderr or "").strip()
|
||||
if not quiet:
|
||||
print("rc=", r.returncode, "|", " | ".join(out[-3:]))
|
||||
if err:
|
||||
print("err=", err[:300])
|
||||
return 0 if r.returncode == 0 else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user