From 6d23ce8768d76c659f3e2dcc01173f495aa56674 Mon Sep 17 00:00:00 2001 From: Ali Al-Arabid Date: Sun, 13 Sep 2026 23:48:49 +0400 Subject: [PATCH] Reduce fallback comment polling frequency --- .env.example | 3 +++ docs/setup.md | 2 +- worker/dm-worker.ts | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 1c3cbd395..b6166f451 100644 --- a/.env.example +++ b/.env.example @@ -8,6 +8,9 @@ ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef DATABASE_URL=postgresql://postgres:postgres@localhost:5432/openreply REDIS_URL=redis://localhost:6379 +# Backup scan for comments missed by Meta webhooks (15 minutes) +COMMENT_POLL_INTERVAL_MS=900000 + # Email magic links (Resend) RESEND_API_KEY=re_... EMAIL_FROM=OpenReply diff --git a/docs/setup.md b/docs/setup.md index 72a64ebe7..0d5b2878a 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -106,7 +106,7 @@ Optional, for tuning the polling reconciler (defaults are fine to start): | Variable | Default | What it does | | --- | --- | --- | -| `COMMENT_POLL_INTERVAL_MS` | `300000` | How often the worker sweeps for missed comments (5 min). | +| `COMMENT_POLL_INTERVAL_MS` | `900000` | How often the worker sweeps for missed comments (15 min). Keep this above your database autosuspend delay. | | `COMMENT_POLL_MAX_PER_SWEEP` | `30` | Max new comments each campaign acts on per sweep. Keep it conservative; higher gets closer to Instagram's rate limits. | | `COMMENT_POLL_LOOKBACK_HOURS` | `72` | How far back a sweep considers comments. | diff --git a/worker/dm-worker.ts b/worker/dm-worker.ts index 4b254d6fa..7dac4e7d2 100644 --- a/worker/dm-worker.ts +++ b/worker/dm-worker.ts @@ -6,10 +6,10 @@ import os from "node:os"; const worker = createDMWorker(); const startedAt = new Date().toISOString(); const HEARTBEAT_INTERVAL_MS = 30_000; -// Polling safety net for comments that webhooks miss. Runs in the worker because -// it must fire every few minutes and Vercel's free crons only run once a day. +// Polling safety net for comments that webhooks miss. Keep this longer than +// Neon's five-minute autosuspend delay so an idle database can scale to zero. const POLL_INTERVAL_MS = Number( - process.env.COMMENT_POLL_INTERVAL_MS ?? 5 * 60_000 + process.env.COMMENT_POLL_INTERVAL_MS ?? 15 * 60_000 ); console.log("[DM Worker] Started");