Show background jobs that finished while TUI was closed

Previously _load_registry silently dropped dead PIDs, so jobs that
completed in the background were invisible on restart. Now dead PIDs
are loaded as 'success' status so the user sees they completed. The
registry is cleaned up after loading.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shuki
2026-03-06 20:46:47 +02:00
parent 0de0f7783a
commit a08cf9911c

View File

@@ -200,25 +200,30 @@ class JobManager:
pid = entry.get("pid") pid = entry.get("pid")
if pid is None: if pid is None:
continue continue
# Check if process is still alive
try:
os.kill(pid, 0)
except (ProcessLookupError, PermissionError):
continue
job_id = entry["id"] job_id = entry["id"]
if job_id in self._jobs: if job_id in self._jobs:
continue continue
# Check if process is still alive
alive = False
try:
os.kill(pid, 0)
alive = True
except (ProcessLookupError, PermissionError):
pass
job = Job( job = Job(
id=job_id, id=job_id,
kind=entry.get("kind", "backup"), kind=entry.get("kind", "backup"),
label=entry.get("label", f"Job (PID {pid})"), label=entry.get("label", f"Job (PID {pid})"),
status="running", status="running" if alive else "success",
started_at=datetime.fromisoformat(entry["started_at"]), started_at=datetime.fromisoformat(entry["started_at"]),
finished_at=None if alive else datetime.now(),
) )
job._pid = pid job._pid = pid
job._pgid = entry.get("pgid") job._pgid = entry.get("pgid")
job._reconnected = True job._reconnected = alive
self._jobs[job.id] = job self._jobs[job.id] = job
# Clean up registry: only keep still-running entries
self._save_registry()
def check_reconnected(self) -> None: def check_reconnected(self) -> None:
changed = False changed = False