Forge.Core Docs
Launch Dashboard

Background Worker

A daily cleanup job runs as its own process, separate from the Fastify API server — no Fastify, no Better Auth init, just MongoDB and a cron schedule.

What it does

  • Purges expired soft-deletes — any member whose 30-day soft-delete grace period has elapsed is permanently removed, cascading to their account, session, two-factor, and passkey rows.
  • Flags unused API keys — active keys idle for 90 days (by last use, or by creation date if never used) get an api_key_unused security event logged, throttled to once per 7-day window per key so a long-stale key doesn't spam the notification feed daily.

Both jobs run once immediately on boot — so a long-stopped worker doesn't leave cleanup stuck — then daily at midnight.

Running it

# dev
yarn workspace forge-core worker

# production, after a build
node dist/worker.js

The worker uses the same FORGE_MONGODB_URI as the main API server — no separate configuration needed.

You still have to run it

This process doesn't start itself, and nothing in this repo schedules it in production — that's deliberately left to your own infrastructure (a second service, a systemd unit, a Kubernetes CronJob, whatever fits how you already deploy the rest of this stack). The API server no longer runs cleanup on an interval itself; if the worker isn't running somewhere, soft-deletes never get purged and unused keys never get flagged.