Events 3.2.0, contracts 1.10.0: the heartbeat says what's on now
stats.live (eventsNow: a session or a one-day event on now, +/- 30 min; checkInsLastHour) so Hub 2.7.0 asks again before an emergency update takes a site with an event on down. Decision 39: emergency updates can run as soon as possible (decision 30 changed). Tests: liveNow, Events 776. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,6 +58,25 @@ async function pendingMigrations() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 3.2.0: what's happening at the church now (heartbeat `stats.live`), so the Hub warns before an
|
||||
* emergency update takes the site down: events with a session on now, or a one-day event (no
|
||||
* sessions, at most 36 hours long) on now, each give or take 30 minutes; and tickets checked in
|
||||
* during the last hour. A multi-week course without a session today doesn't count.
|
||||
*/
|
||||
async function liveNow(now = new Date()) {
|
||||
const soon = new Date(now.getTime() + 30 * 60e3);
|
||||
const recent = new Date(now.getTime() - 30 * 60e3);
|
||||
const [sessions, plain, checkInsLastHour] = await Promise.all([
|
||||
prisma.eventSession.findMany({ where: { cancelledAt: null, startsAt: { lte: soon }, endsAt: { gte: recent }, event: { isActive: true } }, select: { eventId: true } }),
|
||||
prisma.event.findMany({ where: { isActive: true, startDate: { lte: soon }, endDate: { gte: recent }, sessions: { none: {} } }, select: { id: true, startDate: true, endDate: true } }),
|
||||
prisma.ticketUsage.count({ where: { scannedAt: { gte: new Date(now.getTime() - 60 * 60e3) } } }),
|
||||
]);
|
||||
const ids = new Set(sessions.map(x => x.eventId));
|
||||
for (const e of plain) if (new Date(e.endDate) - new Date(e.startDate) <= 36 * 60 * 60e3) ids.add(e.id);
|
||||
return { eventsNow: ids.size, checkInsLastHour };
|
||||
}
|
||||
|
||||
async function disk() {
|
||||
try {
|
||||
const s = await fs.promises.statfs(path.join(__dirname, '..', '..'));
|
||||
@@ -123,11 +142,13 @@ async function stats(now = new Date()) {
|
||||
prisma.payment.aggregate({ where: { createdAt: { gte: yearAgo }, ...EVENT_INCOME }, _sum: { amount: true } }),
|
||||
require('../payments').availableProviders().then(list => list.map(p => p.id)).catch(() => []),
|
||||
]);
|
||||
const live = await liveNow(now).catch(() => undefined);
|
||||
const campusesOn = await campusesEnabled().catch(() => false);
|
||||
const campusCount = campusesOn ? await prisma.campus.count({ where: { archivedAt: null } }) : 0;
|
||||
return {
|
||||
users,
|
||||
events: { active: activeEvents, upcoming: upcomingEvents, total: totalEvents },
|
||||
...(live ? { live } : {}),
|
||||
registrations: { last30d: regs30, total: regsTotal },
|
||||
tickets: { last30d: tickets30, total: ticketsTotal },
|
||||
checkIns: { last30d: checkIns30 },
|
||||
@@ -165,4 +186,4 @@ async function installInfo() {
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { APP_VERSION, incomeBand, health, stats, installInfo };
|
||||
module.exports = { APP_VERSION, incomeBand, health, stats, installInfo, liveNow };
|
||||
|
||||
Reference in New Issue
Block a user