37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""清理58-62号离线Runner"""
|
|
import urllib.request
|
|
import json
|
|
|
|
TOKEN = "1f8058d097e3942a9ed31c44382baf7f08311272"
|
|
BASE = "https://git.xiaoxiajianji.com/api/v1/repos/xiaoxia/xiaoxia-saas/actions/runners"
|
|
|
|
# 查当前列表
|
|
req = urllib.request.Request(BASE, headers={"Authorization": f"token {TOKEN}"})
|
|
with urllib.request.urlopen(req) as resp:
|
|
data = json.loads(resp.read())
|
|
runners = data.get('runners', [])
|
|
offline_58_62 = [r['id'] for r in runners if 58 <= r['id'] <= 62]
|
|
print(f"待清理离线Runner IDs: {offline_58_62}")
|
|
|
|
# 删除
|
|
for rid in offline_58_62:
|
|
del_url = f"{BASE}/{rid}"
|
|
req = urllib.request.Request(del_url, headers={"Authorization": f"token {TOKEN}"}, method="DELETE")
|
|
try:
|
|
with urllib.request.urlopen(req) as resp:
|
|
print(f" Runner {rid}: 删除成功")
|
|
except Exception as e:
|
|
print(f" Runner {rid}: 删除失败 - {e}")
|
|
|
|
# 验证
|
|
req = urllib.request.Request(BASE, headers={"Authorization": f"token {TOKEN}"})
|
|
with urllib.request.urlopen(req) as resp:
|
|
data = json.loads(resp.read())
|
|
runners = data.get('runners', [])
|
|
online = sum(1 for r in runners if r.get('status') == 'online')
|
|
print(f"\n清理后: 共{len(runners)}个Runner,在线{online}个")
|
|
for r in sorted(runners, key=lambda x: x['id']):
|
|
s = "在线" if r.get('status') == 'online' else "离线"
|
|
print(f" ID:{r['id']:2d} {r['name']:30s} {s}")
|