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:
@@ -182,10 +182,22 @@ function restartsInTenMinutes(serverId) {
|
||||
|
||||
// ─── Alerts (§10) ─────────────────────────────────────────────────────────────
|
||||
|
||||
/** The problems a server has now: [{ type, level, message }]. Pure, for tests. */
|
||||
function serverProblems(server, recent, restarts, now = new Date()) {
|
||||
/**
|
||||
* Whether the agent is busy with a job the Hub handed it, still within that job's time limit (and
|
||||
* the 10 minutes the Hub allows on top, as in jobs.poll). Agents before 1.1.1 neither poll nor send
|
||||
* stats while a job runs (an install or update can take 30 minutes), so silence then isn't the
|
||||
* agent being down. Once the limit has passed, the job is failed and silence counts again.
|
||||
*/
|
||||
function busyWithJob(job, now = new Date()) {
|
||||
if (!job || job.status !== 'delivered' || !job.deliveredAt) return false;
|
||||
const limit = ((agent.JOB_TIME_LIMIT_MINUTES[job.type] || 30) + 10) * MIN;
|
||||
return now - new Date(job.deliveredAt) < limit;
|
||||
}
|
||||
|
||||
/** The problems a server has now: [{ type, level, message }]. Pure, for tests. `runningJob`: the job it's running, if any. */
|
||||
function serverProblems(server, recent, restarts, now = new Date(), runningJob = null) {
|
||||
const out = [];
|
||||
if (!server.lastSeenAt || now - new Date(server.lastSeenAt) > 5 * MIN) {
|
||||
if ((!server.lastSeenAt || now - new Date(server.lastSeenAt) > 5 * MIN) && !busyWithJob(runningJob, now)) {
|
||||
out.push({ type: 'agent_silent', level: 'critical', message: server.lastSeenAt ? `The agent hasn't been heard from since ${new Date(server.lastSeenAt).toISOString()}` : 'The agent has never reported' });
|
||||
}
|
||||
const st = server.lastStats;
|
||||
@@ -212,7 +224,8 @@ async function runServerAlerts(now = new Date()) {
|
||||
const cleared = [];
|
||||
for (const server of servers) {
|
||||
const recent = await prisma.serverStat.findMany({ where: { serverId: server.id, granularity: 'minute', at: { gt: new Date(now.getTime() - 6 * MIN) } }, orderBy: { at: 'desc' }, take: 5 });
|
||||
const current = serverProblems(server, recent, restartsInTenMinutes(server.id), now);
|
||||
const running = await prisma.job.findFirst({ where: { serverId: server.id, status: 'delivered' }, orderBy: { deliveredAt: 'desc' } });
|
||||
const current = serverProblems(server, recent, restartsInTenMinutes(server.id), now, running);
|
||||
const open = new Map(server.alerts.map(a => [a.type, a]));
|
||||
for (const p of current) {
|
||||
if (open.has(p.type)) continue;
|
||||
@@ -264,6 +277,7 @@ async function allocatePorts(tx, serverId, now = new Date()) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
busyWithJob,
|
||||
POLL_SECONDS, STATS_SECONDS, newId, hashToken, jobSigningKey, resetJobKeyForTests,
|
||||
createJoinToken, joinCommand, join, requireAgent,
|
||||
serverConfig, setServerConfig, cleanEnvValues, installDefaults,
|
||||
|
||||
Reference in New Issue
Block a user