generated from coulomb/repo-seed
Complete workplan state model cleanup
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
cleanup_stale_tasks.py — cancel tasks that are still open in completed/archived workstreams.
|
||||
cleanup_stale_tasks.py — cancel tasks that are still open in finished/archived workstreams.
|
||||
|
||||
Run manually: python3 scripts/cleanup_stale_tasks.py
|
||||
Run via make: make cleanup-stale
|
||||
@@ -22,6 +22,8 @@ from datetime import datetime, timezone
|
||||
# Make the api package importable when running as `python scripts/cleanup_stale_tasks.py`
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from api.workplan_status import CLOSED_WORKSTREAM_STATUSES, normalize_workstream_status
|
||||
|
||||
try:
|
||||
from api.events import EventEnvelope, publish_event, shutdown_publisher
|
||||
except Exception: # pragma: no cover — event publishing is optional
|
||||
@@ -31,7 +33,7 @@ except Exception: # pragma: no cover — event publishing is optional
|
||||
|
||||
API = "http://127.0.0.1:8000"
|
||||
STALE_STATUSES = {"todo", "in_progress", "blocked"}
|
||||
CLOSED_WS_STATUS = {"completed", "archived"}
|
||||
CLOSED_WS_STATUS = set(CLOSED_WORKSTREAM_STATUSES)
|
||||
|
||||
|
||||
def get(path: str) -> list | dict:
|
||||
@@ -81,7 +83,11 @@ def main() -> int:
|
||||
print("[cleanup-stale] Start the API with: cd ~/state-hub && make api", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
closed_ws = {w["id"]: w for w in workstreams if w["status"] in CLOSED_WS_STATUS}
|
||||
closed_ws = {
|
||||
w["id"]: w
|
||||
for w in workstreams
|
||||
if normalize_workstream_status(w["status"]) in CLOSED_WS_STATUS
|
||||
}
|
||||
|
||||
stale = [
|
||||
t for t in tasks
|
||||
@@ -93,7 +99,7 @@ def main() -> int:
|
||||
print("[cleanup-stale] Nothing to cancel — all open tasks belong to active workstreams.")
|
||||
return 0
|
||||
|
||||
print(f"[cleanup-stale] Found {len(stale)} stale task(s) in completed/archived workstreams:")
|
||||
print(f"[cleanup-stale] Found {len(stale)} stale task(s) in finished/archived workstreams:")
|
||||
|
||||
cancelled = []
|
||||
errors = []
|
||||
@@ -150,7 +156,7 @@ def main() -> int:
|
||||
|
||||
summary = (
|
||||
f"Stale-task cleanup: cancelled {len(cancelled)} task(s) "
|
||||
f"across {len(by_ws)} completed workstream(s)"
|
||||
f"across {len(by_ws)} finished workstream(s)"
|
||||
)
|
||||
detail = {
|
||||
"cancelled_count": len(cancelled),
|
||||
|
||||
Reference in New Issue
Block a user