Files
harheimertc/server/plugins/notification-scheduler.js
Torsten Schulz (local) da1efa5a74
Some checks failed
Code Analysis and Production Deploy / analyze (push) Failing after 5m59s
Code Analysis and Production Deploy / deploy-production (push) Has been skipped
Code Analysis and Production Deploy / deploy-test (push) Has been skipped
Added notifications for actual news
2026-06-11 09:03:16 +02:00

39 lines
1.0 KiB
JavaScript

import { runNotificationSchedulerTick } from '../utils/notification-scheduler.js'
import { info as loggerInfo, error as loggerError } from '../utils/logger.js'
const INTERVAL_MS = 60_000
let timer = null
let running = false
async function tick(reason = 'interval') {
if (running) return
running = true
try {
const result = await runNotificationSchedulerTick()
if (result?.dueUsers) {
loggerInfo('[notification-scheduler] Tick', { reason, ...result })
}
} catch (error) {
loggerError('[notification-scheduler] Tick fehlgeschlagen:', { error })
} finally {
running = false
}
}
export default defineNitroPlugin((nitroApp) => {
if (process.env.NOTIFICATION_SCHEDULER_DISABLED === 'true') {
loggerInfo('[notification-scheduler] Deaktiviert')
return
}
loggerInfo('[notification-scheduler] Gestartet')
timer = setInterval(() => tick(), INTERVAL_MS)
timer.unref?.()
tick('start')
nitroApp.hooks.hookOnce('close', () => {
if (timer) clearInterval(timer)
timer = null
})
})