gabriel / musehub public
backfill_intel_jobs.py python
70 lines 2.4 KB
Raw
sha256:a34090cc4a394a78bd72cbbe34b08cc59525141e19135b6c0ab154f10611b9ef debug(push/stream): instrument O-frame decode path with INF… Sonnet 4.6 patch 122 days ago
1 """One-shot backfill: enqueue intel jobs for specified repos.
2
3 Usage:
4 python deploy/backfill_intel_jobs.py gabriel/muse gabriel/musehub
5 """
6 from __future__ import annotations
7
8 import asyncio
9 import sys
10 import os
11
12 # Ensure app root is on path when run inside the container
13 sys.path.insert(0, "/app")
14
15 from sqlalchemy import select, text
16 from musehub.db.database import AsyncSessionLocal, init_db
17 from musehub.db import musehub_models as db
18 from musehub.services.musehub_jobs import enqueue_job
19
20
21 async def backfill(slugs: list[str]) -> None:
22 await init_db()
23 async with AsyncSessionLocal() as session:
24 for slug in slugs:
25 owner, name = slug.split("/", 1)
26
27 repo_id: str | None = (await session.execute(
28 select(db.MusehubRepo.repo_id).where(
29 db.MusehubRepo.owner == owner,
30 db.MusehubRepo.name == name,
31 ).limit(1)
32 )).scalar_one_or_none()
33
34 if not repo_id:
35 print(f" ✗ {slug} — not found")
36 continue
37
38 # Get head commit for every branch
39 rows = (await session.execute(
40 select(db.MusehubCommit.branch, db.MusehubCommit.commit_id)
41 .where(db.MusehubCommit.repo_id == repo_id)
42 .order_by(db.MusehubCommit.timestamp.desc())
43 )).all()
44
45 if not rows:
46 print(f" ✗ {slug} — no commits")
47 continue
48
49 # Dedupe: keep newest commit per branch
50 seen: set[str] = set()
51 branches: list[tuple[str, str]] = []
52 for branch, commit_id in rows:
53 if branch and branch not in seen:
54 seen.add(branch)
55 branches.append((branch, commit_id))
56
57 for branch, head in branches:
58 payload = {"head": head, "branch": branch}
59 for job_type in ("intel.structural", "intel.code", "push.file_last_commits"):
60 job_id = await enqueue_job(session, repo_id, job_type, payload)
61 status = job_id[:16] + "…" if job_id else "already pending"
62 print(f" ✓ {slug} [{branch}] {job_type} → {status}")
63
64 await session.commit()
65 print("\nAll jobs committed — worker will pick them up.")
66
67
68 if __name__ == "__main__":
69 targets = sys.argv[1:] or ["gabriel/muse", "gabriel/musehub"]
70 asyncio.run(backfill(targets))
File History 1 commit
sha256:a34090cc4a394a78bd72cbbe34b08cc59525141e19135b6c0ab154f10611b9ef debug(push/stream): instrument O-frame decode path with INF… Sonnet 4.6 patch 122 days ago