ZTS Docs

Cron Jobs

This document explains how scheduled tasks (cron jobs) are managed and initiated within the application.

Initiation

Cron job scheduling is primarily initiated within apps/web/instrumentation.ts during server startup (process.env.NEXT_RUNTIME === "nodejs"). This does not run on serverless-only hosts like Vercel without a Node server process.

  • Enable Flag: NEXT_PUBLIC_ENABLE_CRON in packages/env/src/schemas/general.ts must be true.
  • Main Cron Function: startMainCron from apps/web/src/server/instrumentation/cron/scripts/main-cron.ts.
  • Conditional Start: Within instrumentation.ts, the call to startMainCron() is executed only if NEXT_PUBLIC_ENABLE_CRON is true, ensuring that the defined scheduled tasks begin running when the server starts.

Implementation

  • Job Definitions: Individual jobs live under apps/web/src/server/instrumentation/cron/, starting with main-cron.ts.
  • Purpose: Cron jobs are typically used for recurring tasks like database cleanup, sending scheduled reports, syncing data, etc.

Refer to apps/web/src/server/instrumentation/cron/ for implementations and schedules.

On this page