Hub 2.3.1: a server running a job is busy, not down

An agent before 1.1.1 neither polls nor sends stats while it runs a job,
so after 5 minutes the Hub alerted (and emailed) that it was down. While
a job it handed out is within its time limit, the server counts as busy:
no agent_silent alert, online for New install, "Running a job" in the UI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 19:02:49 +02:00
co-authored by Claude Opus 5.5
parent da219c15d4
commit 5a2aec7a67
13 changed files with 76 additions and 21 deletions
+5 -3
View File
@@ -351,8 +351,9 @@ function requireTotp(admin, code) {
if (!verifyCode(decrypt(admin.totpSecret), String(code || '').replace(/\s/g, ''))) throw fail(403, 'BAD_TOTP', 'That two-factor code isn\'t right.');
}
function agentOnline(server, now = new Date()) {
return !!server.lastSeenAt && now - new Date(server.lastSeenAt) < AGENT_ONLINE_MS;
/** Heard from in the last 2 minutes, or busy with a job the Hub handed it (`runningJob`, within its time limit). */
function agentOnline(server, now = new Date(), runningJob = null) {
return (!!server.lastSeenAt && now - new Date(server.lastSeenAt) < AGENT_ONLINE_MS) || servers.busyWithJob(runningJob, now);
}
/** The latest release of a product, or the one asked for (it must exist). */
@@ -371,7 +372,8 @@ async function releaseFor(product, version) {
async function preflight(server, product, version, now) {
if (server.removedAt) throw fail(409, 'SERVER_REMOVED', 'That server was removed.');
if (server.mode !== 'church') throw fail(400, 'NOT_A_CHURCH_SERVER', 'Church sites go on church servers, not the central one.');
if (!agentOnline(server, now)) throw fail(409, 'AGENT_OFFLINE', `The agent on ${server.name} isn't online (last heard ${server.lastSeenAt ? server.lastSeenAt.toISOString() : 'never'}).`);
const running = await prisma.job.findFirst({ where: { serverId: server.id, status: 'delivered' }, orderBy: { deliveredAt: 'desc' } });
if (!agentOnline(server, now, running)) throw fail(409, 'AGENT_OFFLINE', `The agent on ${server.name} isn't online (last heard ${server.lastSeenAt ? server.lastSeenAt.toISOString() : 'never'}).`);
const missing = await missingFor(product, version, servers.serverConfig(server), await servers.installDefaults());
const parts = [];
if (missing.server.length) parts.push(`${server.name}'s configuration needs ${missing.server.join(', ')}`);