Run a Job on a Schedule#

A job is a script plus a cron expression. This example is the script half: it logs the moment it runs, so you can confirm a schedule is firing. Pair it with a schedule and watch the runs arrive.

The Script#

// scheduled-heartbeat.js
const now = new Date();
console.log(`Heartbeat at ${now.toISOString()}`);

How It Works#

  • Each scheduled run executes the file again from the top, so the timestamp reflects the current run.
  • Schedules are evaluated on the server. The job fires on time whether or not the site is open.

Setup#

Name the file scheduled-heartbeat.js, then create a job that points at it. Some useful schedules:

Expression Meaning
*/15 * * * * Every 15 minutes
0 * * * * Every hour, on the hour
0 9 * * 1 Every Monday at 09:00

Run it once with Run now before saving the schedule to confirm the script is correct.