59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""DAG 全链路自动验证:审核放行 → 观察自动触发 → 直至终点任务 done"""
|
|
import json, sys, time, urllib.request
|
|
|
|
BASE = 'http://127.0.0.1:16071'
|
|
COOKIE = '/tmp/aw_cookies.txt'
|
|
|
|
def req(path, method='GET', body=None):
|
|
r = urllib.request.Request(BASE + path, method=method)
|
|
cookie = ''
|
|
for line in open(COOKIE):
|
|
parts = line.strip().split('\t')
|
|
if len(parts) >= 7 and parts[5] and parts[6]:
|
|
cookie += f'{parts[5]}={parts[6]}; '
|
|
r.add_header('Cookie', cookie.strip())
|
|
if body is not None:
|
|
r.add_header('Content-Type', 'application/json')
|
|
data = json.dumps(body).encode()
|
|
else:
|
|
data = None
|
|
with urllib.request.urlopen(r, data=data) as resp:
|
|
return json.loads(resp.read())
|
|
|
|
def task_status(tid):
|
|
d = req(f'/api/tasks/{tid}')['data']
|
|
return d['status'], d.get('costs', [])
|
|
|
|
# 终点任务
|
|
END = int(sys.argv[1]) if len(sys.argv) > 1 else 9
|
|
chain = [4, 5, 6, 7, 8, 9]
|
|
approved = set()
|
|
deadline = time.time() + 900
|
|
|
|
print(f'开始 DAG 全链路验证,终点任务 #{END}')
|
|
while time.time() < deadline:
|
|
all_done = True
|
|
for tid in chain:
|
|
st, costs = task_status(tid)
|
|
mark = f'¥{sum(c["cost"] for c in costs):.4f}' if costs else '-'
|
|
print(f' #{tid}: {st:9s} {mark}', flush=True)
|
|
if st == 'review' and tid not in approved:
|
|
req(f'/api/tasks/{tid}/review', 'POST', {'action': 'approve'})
|
|
approved.add(tid)
|
|
print(f' ✅ 审核通过 #{tid}', flush=True)
|
|
if st != 'done':
|
|
all_done = False
|
|
if all_done:
|
|
print(f'🎉 全链路完成!共审核 {len(approved)} 个任务')
|
|
break
|
|
time.sleep(20)
|
|
else:
|
|
print('⏰ 超时未完成')
|
|
|
|
total = 0
|
|
for tid in chain:
|
|
_, costs = task_status(tid)
|
|
total += sum(c['cost'] for c in costs)
|
|
print(f'总成本: ¥{total:.4f}')
|