fix(quick-260610-i4x-01): replace node-cron schedule() with setInterval in three broker workers

- poller.ts: setInterval(cb, 5 * 60 * 1000) replaces schedule('*/5 * * * *', cb)
- outboxWorker.ts: setInterval(cb, 15 * 1000) replaces schedule('*/15 * * * * *', cb)
- reminderScheduler.ts: setInterval(cb, 60 * 1000) replaces schedule('* * * * *', cb)
- Remove 'import { schedule } from node-cron' from all three files
- Update doc comments to reflect setInterval and document why (node-cron 4.2.1 silent skip)
- Callback bodies and .catch wrappers unchanged; typecheck clean; 91/91 broker tests pass
This commit is contained in:
Lucas Berger
2026-06-10 13:06:56 -04:00
parent 3b87fa4581
commit d9efbc1060
3 changed files with 23 additions and 19 deletions
+8 -5
View File
@@ -1,7 +1,9 @@
/**
* Reminder scheduler — shared-timed-event 15-min reminder scan.
*
* Fires every minute via node-cron. Each tick calls runReminderCheck() which:
* Fires every minute via setInterval. Each tick calls runReminderCheck() which:
* (node-cron 4.2.1 silently skipped scheduled executions in the long-running server
* process; setInterval fires reliably in the same process — replaced to fix the silent skip.)
* 1. Queries shared (isShared=true) timed (allDay=false) events whose dtstartUtc
* falls in (now, now+16min] — strictly after now (future only; excludes
* already-started events) and at most 16 min out. Because the lower bound
@@ -31,7 +33,6 @@
* T-05-19 — per-subscription try/catch; dispatchPush already swallows 410/404.
*/
import { schedule } from 'node-cron'
import { and, eq, gt, lte, sql } from 'drizzle-orm'
import { db } from '../db/client.js'
import { calendars, calendarEvents, pushSubscriptions } from '../db/schema.js'
@@ -201,12 +202,14 @@ export async function runReminderCheck(now = new Date()): Promise<void> {
/**
* Start the 1-minute reminder scan schedule.
* Call once from index.ts's isMainModule() guard — NOT at import time
* (keeps the cron out of the test process; mirrors startBrokerPoller pattern).
* (keeps the setInterval out of the test process; mirrors startBrokerPoller pattern).
* Uses setInterval instead of node-cron: node-cron 4.2.1 silently skipped executions
* in the long-running server process; setInterval fires reliably.
*/
export function startReminderScheduler(): void {
schedule('* * * * *', () => {
setInterval(() => {
runReminderCheck().catch((err: unknown) => {
console.error('[broker/reminderScheduler] Unhandled runReminderCheck error:', err)
})
})
}, 60 * 1000)
}