mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 01:35:39 -04:00
Replace @libsql/client with bun:sqlite for zero-dependency SQLite access, swap drizzle-orm/libsql adapter for drizzle-orm/bun-sqlite, and rewrite Dockerfile to use oven/bun:1-alpine. The raw Database instance is no longer exported via Proxy (native C++ methods lose `this` binding through Reflect.get); instead, a closeDatabase() helper handles graceful shutdown and the health check uses Drizzle's db.run() directly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
export async function onRequestError() {
|
|
// Required by Next.js instrumentation
|
|
}
|
|
|
|
export async function register() {
|
|
if (process.env.NEXT_RUNTIME === "nodejs") {
|
|
// Ensure image cache directories exist (all environments)
|
|
const { ensureImageDirs, imageCacheEnabled } = await import(
|
|
"@/lib/services/image-cache"
|
|
);
|
|
if (imageCacheEnabled()) {
|
|
ensureImageDirs();
|
|
}
|
|
|
|
// Run database migrations on startup
|
|
const { runMigrations } = await import("@/lib/db/migrate");
|
|
runMigrations();
|
|
|
|
// Initialize job scheduler
|
|
const { initJobs } = await import("@/lib/jobs/init");
|
|
initJobs();
|
|
|
|
// Graceful shutdown — stop jobs and close DB on container stop
|
|
const { scheduler } = await import("@/lib/jobs/scheduler");
|
|
const { closeDatabase } = await import("@/lib/db/client");
|
|
|
|
const shutdown = () => {
|
|
console.log("[shutdown] Stopping scheduler...");
|
|
scheduler.stop();
|
|
console.log("[shutdown] Closing database...");
|
|
closeDatabase();
|
|
console.log("[shutdown] Clean shutdown complete");
|
|
process.exit(0);
|
|
};
|
|
|
|
process.on("SIGTERM", shutdown);
|
|
process.on("SIGINT", shutdown);
|
|
}
|
|
}
|