# Cron jobs

PREREQUISITES

The cron.enabled configuration option should be set to true in the ./config/server.js (or./config/server.ts for TypeScript projects) file.

cron allows scheduling arbitrary functions for execution at specific dates, with optional recurrence rules. These functions are named cron jobs. cron only uses a single timer at any given time, rather than reevaluating upcoming jobs every second/minute.

This feature is powered by the node-schedule (opens new window) package.

The cron format consists of:


*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    |
│    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sun)
│    │    │    │    └───── month (1 - 12)
│    │    │    └────────── day of month (1 - 31)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)

To define cron jobs and have them run at the required times:

  1. Create the appropriate file.
  2. Enable the cron jobs in the server configuration file.

💡 TIP

Optionally, cron jobs can be directly created in the cron.tasks key of the server configuration file.

# Creating a cron job

To define a cron job, create a file with the following structure:

If the cron job requires running on a specific timezone:

# Enabling cron jobs

To enable cron jobs, set cron.enabled to true in the server configuration file and declare the jobs: