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 -8
View File
@@ -1,5 +1,5 @@
/**
* CalDAV broker poller — runs every 5 minutes via node-cron.
* CalDAV broker poller — runs every 5 minutes via setInterval.
*
* Responsibilities (D-13, D-02):
* - Load all member_credentials (N-credential per-member model)
@@ -10,12 +10,10 @@
* → ctag changed or null: call syncCalendar (REPORT → ical.js → DB upsert)
*
* runPoll is exported for unit testing (inject mocks via vi.mock at the module level).
* startBrokerPoller wraps it in node-cron's 5-minute schedule.
*
* Source: https://github.com/node-cron/node-cron (v4 stable basic API)
* startBrokerPoller wraps it in a 5-minute setInterval.
* (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.)
*/
import { schedule } from 'node-cron'
import { and, eq } from 'drizzle-orm'
import { db } from '../db/client.js'
import { memberCredentials, calendars } from '../db/schema.js'
@@ -91,11 +89,13 @@ export async function runPoll(): Promise<void> {
/**
* Starts the 5-minute background polling schedule.
* Call once at API startup (Plan 04 wires this into index.ts).
* 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 startBrokerPoller(): void {
schedule('*/5 * * * *', () => {
setInterval(() => {
runPoll().catch((err: unknown) => {
console.error('[broker/poller] Unhandled runPoll error:', err)
})
})
}, 5 * 60 * 1000)
}