Website 1.4.0: nightly database backups and background jobs
As Accounts and Cross Events: a gzipped pg_dump every night (02:20) into backend/backups/, the same website-*.sql.gz files crosscode makes before updates, with Admin -> Backups (back up now, download, how many to keep). The heartbeat, event feed and YouTube move from plain timers onto pg-boss with the backup, and Admin -> Background jobs switches each on or off, changes its schedule or runs it now. The heartbeat now reports the newest backup (before: always none, so the Hub warned) and the real job state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,8 @@ import { connectAccountsIfListed } from '../links/connect.js';
|
||||
import { keyPair, saveLinkedProducts } from '../links/store.js';
|
||||
import { hubPublicKey, verifyToken } from './licence.js';
|
||||
import { storage } from '../admin/media.js';
|
||||
import { lastBackupAt } from '../backups/backups.js';
|
||||
import { jobsHealth } from '../jobs.js';
|
||||
|
||||
export const PROTOCOL_VERSION = 2;
|
||||
const TIMEOUT_MS = 15000;
|
||||
@@ -62,8 +64,10 @@ export async function health(ctx: Ctx) {
|
||||
return {
|
||||
uptimeSeconds: Math.round((Date.now() - STARTED_AT) / 1000),
|
||||
db: await dbUp(ctx),
|
||||
jobs: { mode: ctx.config.jobsEnabled ? 'queue' : 'off', failedLast24h: 0 },
|
||||
lastBackupAt: null,
|
||||
// 1.4.0: the real job mode and failures, and the newest backup (before: always null, so the
|
||||
// Hub warned "No backup reported").
|
||||
jobs: await jobsHealth(ctx),
|
||||
lastBackupAt: (await lastBackupAt(ctx).catch(() => null))?.toISOString() ?? null,
|
||||
disk: null,
|
||||
errorsLast24h: null,
|
||||
pendingMigrations: 0,
|
||||
@@ -190,16 +194,6 @@ export async function connectFromEnv(ctx: Ctx, { attempts = 5, delayMs = 60_000
|
||||
return { connected: false, reason: 'unreachable' };
|
||||
}
|
||||
|
||||
/** Heartbeats every 15 minutes until stopped (pg-boss comes with the Website's other jobs). */
|
||||
export function startHeartbeats(ctx: Ctx): () => void {
|
||||
if (!ctx.config.jobsEnabled) return () => {};
|
||||
const timer = setInterval(() => {
|
||||
heartbeat(ctx).catch((e) => console.warn('[hub] Heartbeat failed:', (e as Error).message));
|
||||
}, 15 * 60 * 1000);
|
||||
timer.unref?.();
|
||||
return () => clearInterval(timer);
|
||||
}
|
||||
|
||||
/**
|
||||
* "Get more storage" (WEBSITE-1.0-PLAN §10, decision 12; contracts 1.18.0): asks the Hub for more
|
||||
* 5 GB steps. The Hub emails Cross Code; the new limit arrives with a later heartbeat answer.
|
||||
|
||||
Reference in New Issue
Block a user