-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstrumentation.ts
More file actions
50 lines (41 loc) · 1.91 KB
/
Copy pathinstrumentation.ts
File metadata and controls
50 lines (41 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* Next.js Instrumentation Hook
* This file is executed once when the server starts
* https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation
*/
export async function register() {
console.log("[Instrumentation] register() called");
console.log("[Instrumentation] NEXT_RUNTIME:", process.env.NEXT_RUNTIME);
// Only run on server
if (process.env.NEXT_RUNTIME === "nodejs") {
// Configure transformers.js to use WASM backend ONLY
// This must happen BEFORE any code imports @xenova/transformers
// Fallback safety check in case container env vars aren't set
if (!process.env.TRANSFORMERS_BACKEND) {
process.env.TRANSFORMERS_BACKEND = "wasm";
console.log("[Instrumentation] Set TRANSFORMERS_BACKEND=wasm (fallback)");
}
if (!process.env.ONNXRUNTIME_EXECUTION_PROVIDERS) {
process.env.ONNXRUNTIME_EXECUTION_PROVIDERS = "wasm";
console.log("[Instrumentation] Set ONNXRUNTIME_EXECUTION_PROVIDERS=wasm (fallback)");
}
if (!process.env.USE_ONNX_WASM) {
process.env.USE_ONNX_WASM = "1";
console.log("[Instrumentation] Set USE_ONNX_WASM=1 (fallback)");
}
console.log("[Instrumentation] Transformers.js configured for WASM-only backend");
console.log("[Instrumentation] Running in Node.js runtime, initializing scheduler...");
const { initializeScheduler } = await import("./src/lib/jobs/scheduler");
const { registerShutdownHandlers } = await import("./src/lib/process-manager");
const { memoryMonitor } = await import("./src/lib/memory-monitor");
// Initialize cron jobs
initializeScheduler();
// Register graceful shutdown handlers
registerShutdownHandlers();
// Start memory monitoring
memoryMonitor.start();
console.log("[Instrumentation] Scheduler initialization complete");
} else {
console.log("[Instrumentation] Not in Node.js runtime, skipping scheduler initialization");
}
}