Skip to content

Cron (Scheduled)

You can schedule code to run repeatedly on Val Town. Want to check an RSS feed every hour, or send a reminder email every day? This is how to do it: just create a scheduled function and specify when it should run.

Type Signature

Cron functions should take an Interval object as a parameter, and can return anything as a result. The return value is ignored.

ExampleRun in Val Town ↗
export function cronValHandler(interval: Interval) {
console.log("Cron val ran!");
}

The Interval type has the following shape:

interface Interval {
lastRunAt: Date | undefined;
}

Schedule types

There are two kinds of schedules: either simple intervals, like “run every two hours”, or you can use cron syntax to define more complex schedules.

You can consult crongpt.com for help on writing cron expressions. For example the following cron runs every two hours, on the first day of the month:

0 */2 1 * *

Example

This example polls an RSS feed for new items since the last run.