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
View File
@@ -16,6 +16,7 @@ import githubRouter from "./routes/github.js";
import reposRouter from "./routes/repos.js"; import reposRouter from "./routes/repos.js";
import { attachWebSocket, createTerminalSession } from "./services/terminal.service.js"; import { attachWebSocket, createTerminalSession } from "./services/terminal.service.js";
import { attachLspWebSocket } from "./services/lsp.service.js"; import { attachLspWebSocket } from "./services/lsp.service.js";
import { startUpstreamPolling } from "./services/git.service.js";
const __dirname = path.dirname(fileURLToPath(import.meta.url)); const __dirname = path.dirname(fileURLToPath(import.meta.url));
const app = express(); const app = express();
@@ -77,4 +78,5 @@ server.on("upgrade", (request, socket, head) => {
const PORT = parseInt(process.env.PORT || "3000", 10); const PORT = parseInt(process.env.PORT || "3000", 10);
server.listen(PORT, "0.0.0.0", () => { server.listen(PORT, "0.0.0.0", () => {
console.log(`Layonara Forge listening on http://0.0.0.0:${PORT}`); console.log(`Layonara Forge listening on http://0.0.0.0:${PORT}`);
startUpstreamPolling();
}); });
@@ -2,6 +2,7 @@ import simpleGit, { SimpleGit } from "simple-git";
import fs from "fs/promises"; import fs from "fs/promises";
import { REPOS, type RepoName } from "../config/repos.js"; import { REPOS, type RepoName } from "../config/repos.js";
import { getRepoPath, readConfig } from "./workspace.service.js"; import { getRepoPath, readConfig } from "./workspace.service.js";
import { broadcast } from "./ws.service.js";
function git(repoPath: string): SimpleGit { function git(repoPath: string): SimpleGit {
return simpleGit(repoPath); return simpleGit(repoPath);
@@ -174,3 +175,35 @@ export async function listReposWithStatus() {
return results; 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;
}
}