33 lines
1.7 KiB
Python
33 lines
1.7 KiB
Python
"""Cancel only the user's cleared Huobao jobs, identified by private bridge records."""
|
|
import sqlite3,json,subprocess,pathlib,base64
|
|
root=pathlib.Path('/home/ps/huobao-gpu-selection')
|
|
known=set()
|
|
for loc in ('/home/ps/huobao-model-bridge/state/jobs.sqlite3','/home/ps/huobao-vdn/bridge-state/jobs.sqlite3'):
|
|
with sqlite3.connect(loc) as db:
|
|
for table in ('jobs','image_jobs'):
|
|
for (encoded,) in db.execute('select id from '+table):
|
|
try:
|
|
raw=encoded.removeprefix('h3v2.');known.add(base64.urlsafe_b64decode(raw+'='*(-len(raw)%4)).decode().split(':',1)[1])
|
|
except Exception:pass
|
|
code='''import asyncio,httpx,json,app
|
|
KNOWN=__KNOWN__
|
|
async def main():
|
|
async with httpx.AsyncClient(timeout=30) as c:
|
|
removed=[]
|
|
for p in app.providers().values():
|
|
headers=app.provider_headers(p)
|
|
q=(await c.get(p.base_url+'/queue',headers=headers)).json()
|
|
ids=[x[1] for x in q.get('queue_pending',[]) if x[1] in KNOWN]
|
|
if ids:
|
|
r=await c.post(p.base_url+'/queue',headers=headers,json={'delete':ids});r.raise_for_status();removed+=ids
|
|
q=(await c.get(p.base_url+'/queue',headers=headers)).json()
|
|
running=[x[1] for x in q.get('queue_running',[])]
|
|
if running and all(x in KNOWN for x in running):
|
|
r=await c.post(p.base_url+'/interrupt',headers=headers,json={});r.raise_for_status();removed+=running
|
|
print(json.dumps({'worker':p.id,'removed_pending':ids,'interrupted_running':[x for x in running if x in KNOWN],'unrelated_kept':[x for x in running if x not in KNOWN]}))
|
|
print('CANCELLED_IDS='+json.dumps(removed))
|
|
asyncio.run(main())
|
|
'''.replace('__KNOWN__',repr(known))
|
|
out=subprocess.check_output(['docker','exec','huobao-vdn-normalizer','python','-c',code],text=True)
|
|
print(out);(root/'cancelled-huobao-jobs.txt').write_text(out)
|