API Worker
A separate Node process, sharing the API codebase, that runs all scheduled (cron) and queued background work — so the web-facing API stays responsive.
macaroni-kid-2.api → workers/workers/index.js (npm run start:worker)Dockerfile.worker (Node 18)node-cron (timezone-aware, America/New_York)api-3 Linode (50.116.60.72) — which, unlike the production API nodes, does not run PM2. The repo's Dockerfile.worker defines the image; Coolify (control plane on the separate coolify host, 50.116.54.22) builds and runs it. See Environments & Deployment for the full inventory.
What it does
On startup the worker begins connection monitoring (services/connectionMonitor), starts queue workers (scheduled article publishing, publication updates, newsletter refresh), and registers the cron jobs below. Global error handlers keep it alive through individual job failures.
Scheduled jobs
Thirteen cron jobs are registered (a few retry variants are present but commented out). They were consolidated here from what used to be several separate API servers.
| Schedule (ET) | Job | What it does |
|---|---|---|
| 00:30 daily | getCampaignStats | Publication/campaign metrics |
| every 5 min | resetUpdatingStats | Clears stuck "updating" flags on publications |
| every 5 min | auto-publishing checkStatus | Monitors auto-publish newsletter runs |
| hourly | publishArticles / publishEvents / publishBusinesses | Publishes scheduled content & indexes it |
| 03:00 daily | reIndexFailedObjects | Retries failed OpenSearch indexing (FailedIndex) |
| 06:00 daily | initiateOngageRecount | Reconciles subscriber counts with Ongage |
| 00:10 daily | updateSubscriberCount | Refreshes per-town subscriber counts |
| 05:00 daily | updateAds | Activates/expires ad campaigns |
| 23:30 daily | updateCronStats | Nightly town statistics rollup |
| Wed 11:05am | auto-publishing — No-Publisher towns | Auto-publishes newsletters for towns without an active publisher |
| Thu 3:00pm | auto-publishing — Publisher towns | Auto-publishes newsletters for publisher towns |
Schedules above are summarized from the node-cron expressions in workers/index.js; retry jobs for the two auto-publishing runs exist in the file but are currently commented out.
Queue workers
Beyond cron, the worker starts longer-running queue processors from workers/: scheduleArticle, updatePublication, and updateAllNewsletters (with schedulePublication / publicationQueue present but disabled). These coordinate scheduled publishing and newsletter regeneration, backed by Redis/Mongo-based queues.
app.js notes: "cron jobs now handled by worker process." This keeps long jobs from blocking request handling and lets the two scale independently.