首次提交
This commit is contained in:
41
tools/release_machine.py
Normal file
41
tools/release_machine.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""人工救援: 当某台机器【永久报废】(不会再重启续做)时, 把它名下所有未完成分片的锁删掉,
|
||||
任务退回 todo 让别的机器重新认领。
|
||||
|
||||
⚠️ 只在确认机器真报废后用。机器只是重启的话, 它自己会续做, 不要跑这个。
|
||||
|
||||
用法:
|
||||
python tools/release_machine.py <机器ID> # 实际释放
|
||||
python tools/release_machine.py <机器ID> --dry-run # 只列出, 不删
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
from tool import job_cos # noqa: E402
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("用法: python tools/release_machine.py <机器ID> [--dry-run]")
|
||||
sys.exit(1)
|
||||
target = sys.argv[1]
|
||||
dry = "--dry-run" in sys.argv[2:]
|
||||
|
||||
shards = job_cos.my_open_claims(target)
|
||||
if not shards:
|
||||
print(f"机器 {target} 名下没有未完成分片。")
|
||||
return
|
||||
print(f"机器 {target} 名下未完成分片 {len(shards)} 个:")
|
||||
for s in shards:
|
||||
print(f" - {s}")
|
||||
if dry:
|
||||
print("(--dry-run, 未删除)")
|
||||
return
|
||||
for s in shards:
|
||||
job_cos._delete(job_cos._key("claimed", s)) # 只删锁; todo 仍在 -> 别人会重领
|
||||
print(f"✓ 已释放 {len(shards)} 个分片的锁, 它们会被其他机器重新认领。")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user