Hub 2.7.0: emergency updates as soon as possible; events on now need a second yes
asap (emergency only, reason + 2FA) queues the update now; the church is told it's happening now. A church whose Events heartbeat reports an event on now (stats.live, Events 3.2.0) refuses an emergency update with LIVE_EVENT until confirmLive. Both update forms offer "As soon as possible" and ask again for a live event. Contracts 1.10.0 vendored. 4 new tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -700,13 +700,29 @@ async function accountsPlan(d, release, accountsRelease) {
|
||||
return { version: `accounts@${accountsRelease.version}`, install: { domain, release: accountsRelease }, note: `${d.shortName}: Accounts ${accountsRelease.version} is installed first at ${domain} (${PRODUCT_NAMES[d.product]} ${release.version} needs it).` };
|
||||
}
|
||||
|
||||
async function scheduleUpdate({ deploymentIds, product: wanted = null, version, at, emergency = false, reason = null, totp = null }, admin, now = new Date()) {
|
||||
const when = new Date(at);
|
||||
/**
|
||||
* What's happening at a church now (Hub 2.7.0), from its Cross Events install's last heartbeat
|
||||
* (`stats.live`, Events 3.2.0+; a heartbeat older than 30 minutes doesn't count). An Accounts update
|
||||
* takes Events' sign-in down too, so it looks at the church's Events. Null when nothing is known.
|
||||
*/
|
||||
async function liveAt(d, now = new Date()) {
|
||||
const ev = d.product === 'events' ? d : await prisma.deployment.findFirst({ where: { shortName: d.shortName, product: 'events', status: { notIn: ['removed', 'failed'] } }, include: { install: true } });
|
||||
const install = ev?.install;
|
||||
const live = install?.stats?.live;
|
||||
if (!live || !install.lastHeartbeatAt || now - new Date(install.lastHeartbeatAt) > 30 * MIN) return null;
|
||||
return { eventsNow: Number(live.eventsNow) || 0, checkInsLastHour: Number(live.checkInsLastHour) || 0 };
|
||||
}
|
||||
|
||||
async function scheduleUpdate({ deploymentIds, product: wanted = null, version, at, emergency = false, asap = false, confirmLive = false, reason = null, totp = null }, admin, now = new Date()) {
|
||||
// Hub 2.7.0: an emergency update can run as soon as possible (the agent's next poll, within a
|
||||
// minute) instead of at a time at least 15 minutes away (decision 30, changed 2026-11-19).
|
||||
if (asap && !emergency) throw fail(400, 'BAD_REQUEST', 'Only an emergency update runs as soon as possible.');
|
||||
const when = asap ? now : new Date(at);
|
||||
if (Number.isNaN(when.getTime())) throw fail(400, 'BAD_REQUEST', 'Pick a time.');
|
||||
if (emergency) {
|
||||
if (!reason || !String(reason).trim()) throw fail(400, 'BAD_REQUEST', 'An emergency update needs a reason (it goes in the email and banner).');
|
||||
requireTotp(admin, totp);
|
||||
if (when - now < EMERGENCY_MIN_MINUTES * MIN) throw fail(400, 'TOO_SOON', `An emergency update needs at least ${EMERGENCY_MIN_MINUTES} minutes' notice.`);
|
||||
if (!asap && when - now < EMERGENCY_MIN_MINUTES * MIN) throw fail(400, 'TOO_SOON', `An emergency update at a time needs at least ${EMERGENCY_MIN_MINUTES} minutes' notice (or choose as soon as possible).`);
|
||||
} else if (when - now < SCHEDULE_MIN_HOURS * HOUR) {
|
||||
throw fail(400, 'TOO_SOON', `Updates are planned at least ${SCHEDULE_MIN_HOURS} hours ahead (or as an emergency update).`);
|
||||
}
|
||||
@@ -724,6 +740,21 @@ async function scheduleUpdate({ deploymentIds, product: wanted = null, version,
|
||||
const accountsRelease = product === 'accounts' ? null : await prisma.release.findMany({ where: { product: 'accounts' } }).then(rs => rs.sort((a, b) => compareVersions(b.version, a.version))[0] || null);
|
||||
const plans = new Map();
|
||||
const warnings = [];
|
||||
// An emergency update takes a site down with little or no notice: a church with an event on now
|
||||
// (people checking in, a session running) is named, and the update waits for a second "yes".
|
||||
if (emergency) {
|
||||
const busy = [];
|
||||
for (const d of deployments) {
|
||||
const live = await liveAt(d, now);
|
||||
if (live && (live.eventsNow > 0 || live.checkInsLastHour > 0)) {
|
||||
busy.push(`${d.shortName} (${[live.eventsNow ? `${live.eventsNow} event(s) on now` : '', live.checkInsLastHour ? `${live.checkInsLastHour} check-in(s) in the last hour` : ''].filter(Boolean).join(', ')})`);
|
||||
}
|
||||
}
|
||||
if (busy.length && !confirmLive) {
|
||||
throw fail(409, 'LIVE_EVENT', `An event is on now at ${busy.join('; ')}. The site will be down for a few minutes during the update: people checking in or registering will be interrupted. Update anyway?`);
|
||||
}
|
||||
if (busy.length) warnings.push(`Updated while an event was on: ${busy.join('; ')}.`);
|
||||
}
|
||||
for (const d of deployments) {
|
||||
if (d.status !== 'live') throw fail(409, 'NOT_LIVE', `${d.shortName} isn't live (${d.status}).`);
|
||||
if (d.server.removedAt) throw fail(409, 'SERVER_REMOVED', `${d.shortName}'s server was removed.`);
|
||||
@@ -769,7 +800,9 @@ async function scheduleUpdate({ deploymentIds, product: wanted = null, version,
|
||||
jobs.push(acc);
|
||||
}
|
||||
const title = emergency ? `Urgent ${name} update` : `Planned ${name} update`;
|
||||
const message = `${name} will be updated on ${sast(when)}. The site will be unavailable for a few minutes.${emergency ? ` Why: ${reason}` : ''}`;
|
||||
const message = asap
|
||||
? `${name} is being updated now. The site will be unavailable for a few minutes. Why: ${reason}`
|
||||
: `${name} will be updated on ${sast(when)}. The site will be unavailable for a few minutes.${emergency ? ` Why: ${reason}` : ''}`;
|
||||
const noticeId = await addNotice(d, { title, message, endsAt: new Date(when.getTime() + 2 * HOUR), level: emergency ? 'warning' : 'maintenance' }, now);
|
||||
// Accounts goes first in the same deploy: told its version, so it's never changed by surprise.
|
||||
const versions = [...(plan.version && !plan.install ? [plan.version] : []), `${product}@${release.version}`];
|
||||
@@ -779,7 +812,7 @@ async function scheduleUpdate({ deploymentIds, product: wanted = null, version,
|
||||
args: { church: d.shortName, products: [product], versions },
|
||||
}));
|
||||
const notes = release.notes ? `\n\nWhat's new in ${release.version}:\n${release.notes}` : '';
|
||||
await emailSiteAdmin(d, `${emergency ? 'Urgent: ' : ''}${name} will be updated on ${sast(when)}`, `${message}${notes}`);
|
||||
await emailSiteAdmin(d, asap ? `Urgent: ${name} is being updated now` : `${emergency ? 'Urgent: ' : ''}${name} will be updated on ${sast(when)}`, `${message}${notes}`);
|
||||
}
|
||||
return { jobs, batchId, warnings: [...new Set(warnings)] };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user