refactor(cron): check for usable git in run_sweep, not in scheduler.py
20b1843f34 put the check at the top of _worktree_maintenance_repos, which
grew cron/scheduler.py, a file already past the 2,000-line cap. Move it
to run_sweep in scheduler_worktree_maintenance.py, before the sweep claims
its slot or any repo, so no sweep runs discovery or a prune without a
usable git. In scheduler.py, keep the job-workdir probe's own resolution
(the cherry-picked cron fix) and fold two lines, so this PR leaves the
file at its base length.
This commit is contained in:
@@ -3981,13 +3981,6 @@ def _worktree_maintenance_repos() -> list[str]:
|
||||
"""Repos whose ``.worktrees/`` to keep pruned: the hermes checkout, job workdir repo roots and
|
||||
every repo this profile created a worktree in (``worktree_registry``), filtered to those that
|
||||
actually have a ``.worktrees/`` dir."""
|
||||
from hermes_platform.resolver.git import resolve_usable_git
|
||||
|
||||
git = resolve_usable_git()
|
||||
if git is None:
|
||||
# The prune runs git in every repo found here: with no usable git (missing, or macOS's CLT
|
||||
# stub, whose every launch opens Apple's install dialog) there is nothing to sweep.
|
||||
return []
|
||||
repos: set = set()
|
||||
|
||||
with contextlib.suppress(Exception):
|
||||
@@ -4002,16 +3995,16 @@ def _worktree_maintenance_repos() -> list[str]:
|
||||
|
||||
with contextlib.suppress(Exception):
|
||||
from cron.jobs import load_jobs
|
||||
from hermes_platform.resolver.git import resolve_usable_git
|
||||
|
||||
for job in load_jobs():
|
||||
for job in load_jobs() if (git := resolve_usable_git()) else ():
|
||||
workdir = str(job.get("workdir") or "").strip()
|
||||
if not workdir or not Path(workdir).is_dir():
|
||||
continue
|
||||
try:
|
||||
probe = subprocess.run(
|
||||
[git, "-C", workdir, "rev-parse", "--show-toplevel"],
|
||||
capture_output=True, text=True, encoding="utf-8",
|
||||
errors="replace", timeout=5, check=False)
|
||||
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=5, check=False)
|
||||
if probe.returncode == 0 and probe.stdout.strip():
|
||||
repos.add(probe.stdout.strip())
|
||||
except Exception:
|
||||
|
||||
@@ -19,6 +19,8 @@ import threading
|
||||
import time
|
||||
from typing import Callable, Iterable, Optional
|
||||
|
||||
from hermes_platform.resolver.git import resolve_usable_git
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Bounded so a wedged sweep cannot park a profile's thread forever; a normal sweep is one git pass
|
||||
@@ -63,6 +65,10 @@ def run_sweep(discover: Callable[[], Iterable[str]], *, interval_seconds: float,
|
||||
``discover`` stays in the caller so a per-profile repo lookup (and anything a test patches) is
|
||||
read where it is defined. Errors never propagate: GC is hygiene, not scheduling.
|
||||
"""
|
||||
if resolve_usable_git() is None:
|
||||
# The job-workdir probe and every prune run git: with none usable (missing, or macOS's
|
||||
# CLT stub, whose every launch opens Apple's install dialog) there is nothing to sweep.
|
||||
return
|
||||
if not claim_sweep_slot(wait_seconds):
|
||||
logger.debug("Cron worktree maintenance skipped: another sweep is still running")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user