Codebase

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.

Lives in
macaroni-kid-2.apiworkers/
Entry point
workers/index.js (npm run start:worker)
Container
Dockerfile.worker (Node 18)
Deployment
Managed via Coolify (self-hosted PaaS) — not evident from the repo alone
Scheduler
node-cron (timezone-aware, America/New_York)
Deployed with Coolify on api-3
The worker runs under Coolify (a self-hostable PaaS) on the 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)JobWhat it does
00:30 dailygetCampaignStatsPublication/campaign metrics
every 5 minresetUpdatingStatsClears stuck "updating" flags on publications
every 5 minauto-publishing checkStatusMonitors auto-publish newsletter runs
hourlypublishArticles / publishEvents / publishBusinessesPublishes scheduled content & indexes it
03:00 dailyreIndexFailedObjectsRetries failed OpenSearch indexing (FailedIndex)
06:00 dailyinitiateOngageRecountReconciles subscriber counts with Ongage
00:10 dailyupdateSubscriberCountRefreshes per-town subscriber counts
05:00 dailyupdateAdsActivates/expires ad campaigns
23:30 dailyupdateCronStatsNightly town statistics rollup
Wed 11:05amauto-publishing — No-Publisher townsAuto-publishes newsletters for towns without an active publisher
Thu 3:00pmauto-publishing — Publisher townsAuto-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.

Why it's separate
Cron and queue work was deliberately moved out of the web API process. The API's app.js notes: "cron jobs now handled by worker process." This keeps long jobs from blocking request handling and lets the two scale independently.