Files
sofa/instrumentation.ts
T
jakeandClaude Opus 4.6 e59364e126 Add database backup/restore feature with admin UI
- Backup service using VACUUM INTO for WAL-safe atomic snapshots
- Server-side storage in DATA_DIR/backups with download/upload API routes
- Restore with integrity validation and automatic pre-restore safety backup
- Scheduled daily backups via cron with configurable retention
- Admin-only settings UI consolidated under single Server section
- Clean up account section sign-out button, fix switch sub-pixel rendering

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 20:01:10 -05:00

46 lines
1.3 KiB
TypeScript

export async function onRequestError() {
// Required by Next.js instrumentation
}
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
const { createLogger } = await import("@/lib/logger");
const log = createLogger("server");
// Ensure image cache directories exist (all environments)
const { ensureImageDirs, imageCacheEnabled } = await import(
"@/lib/services/image-cache"
);
if (imageCacheEnabled()) {
ensureImageDirs();
}
// Ensure backup directory exists
const { ensureBackupDir } = await import("@/lib/services/backup");
ensureBackupDir();
// Run database migrations on startup
const { runMigrations } = await import("@/lib/db/migrate");
runMigrations();
// Initialize job scheduler
const { startJobs, stopJobs } = await import("@/lib/cron");
startJobs();
// Graceful shutdown — stop jobs and close DB on container stop
const { closeDatabase } = await import("@/lib/db/client");
const shutdown = () => {
log.info("Stopping scheduler...");
stopJobs();
log.info("Closing database...");
closeDatabase();
log.info("Clean shutdown complete");
process.exit(0);
};
process.on("SIGTERM", shutdown);
process.on("SIGINT", shutdown);
}
}