feat: add upstream repo polling every 15 minutes

This commit is contained in:
plenarius
2026-04-20 21:55:52 -04:00
parent 3784d9f13a
commit b224ebc927
2 changed files with 35 additions and 0 deletions
@@ -2,6 +2,7 @@ import simpleGit, { SimpleGit } from "simple-git";
import fs from "fs/promises";
import { REPOS, type RepoName } from "../config/repos.js";
import { getRepoPath, readConfig } from "./workspace.service.js";
import { broadcast } from "./ws.service.js";
function git(repoPath: string): SimpleGit {
return simpleGit(repoPath);
@@ -174,3 +175,35 @@ export async function listReposWithStatus() {
return results;
}
const lastKnownBehind = new Map<string, number>();
let pollingInterval: ReturnType<typeof setInterval> | null = null;
export function startUpstreamPolling(intervalMs: number = 900000): void {
if (pollingInterval) return;
pollingInterval = setInterval(async () => {
for (const repo of REPOS) {
try {
const repoPath = getRepoPath(repo.name);
await fs.access(repoPath);
const behind = await fetchUpstream(repoPath);
const prev = lastKnownBehind.get(repo.name) || 0;
if (behind !== prev) {
lastKnownBehind.set(repo.name, behind);
if (behind > 0) {
broadcast("git", "upstream-update", { repo: repo.name, behind });
}
}
} catch {
// repo not cloned or fetch failed
}
}
}, intervalMs);
}
export function stopUpstreamPolling(): void {
if (pollingInterval) {
clearInterval(pollingInterval);
pollingInterval = null;
}
}