forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstrumentation.ts
More file actions
33 lines (29 loc) · 1.13 KB
/
instrumentation.ts
File metadata and controls
33 lines (29 loc) · 1.13 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
// src/instrumentation.ts
//
// Next.js server boot hook. Recovers the scheduler from a persisted
// encryption key so polling survives container restarts without login.
export async function register() {
// Only run on Node.js runtime (not Edge)
if (process.env.NEXT_RUNTIME !== "nodejs") return
const { loadSchedulerKey } = await import("@/lib/scheduler-key-store")
const { startScheduler } = await import("@/lib/scheduler")
const { log } = await import("@/lib/logger")
const { shouldSecureCookies } = await import("@/lib/cookie-security")
if (!shouldSecureCookies()) {
log.warn(
"Session cookies are not marked Secure. If this instance is served over HTTPS, " +
"set BASE_URL=https://... or SECURE_COOKIES=true in your environment."
)
}
try {
const key = await loadSchedulerKey()
if (!key) {
log.info("No persisted scheduler key — polling will start after first login")
return
}
startScheduler(key)
log.info("Scheduler restored from persisted key on boot")
} catch (err) {
log.warn({ err }, "Boot-time scheduler recovery failed — will start after next login")
}
}