Cron And Intervals

by val-town2d3ec654b6a7No licenseListed Oct 8, 2026Updated Oct 8, 2026

Use when building a val that runs on a schedule — periodic jobs, recurring tasks, polling, cron jobs, monitoring, alerting. Covers the interval handler signature, cron expressions, the UTC timezone constraint, and the `lastRunAt` pattern for detecting new items since the previous run.

Instructions onlySoftware Development
AI-generated overview

Guides writing scheduled interval vals with cron expressions, UTC timezone rules, and the lastRunAt pattern.

What it does
This skill provides instructions for building interval-type vals that run on a recurring cron schedule. It documents the interval handler signature, the UTC timezone constraint for cron expressions, and the lastRunAt pattern for fetching only items created since the previous run. It also covers reading and updating interval settings, when to skip a template, and verifying changes by running the handler manually.
When to use it
Use it when creating or editing a scheduled val for periodic jobs, recurring tasks, polling, monitoring, or alerting. It fits work that should happen on a clock rather than in response to a request.
Requirements
No scripts are shipped; it is instructions only. It assumes a val platform with interval-type files, the read_interval_settings and write_interval_settings tools, and the run_file tool for manual verification.

Cron / Interval Vals

Interval vals (fileType: "interval") run on a recurring schedule defined by a cron expression. Use them for polling external APIs, sending reminders, running cleanups, generating reports, or any work that should happen on a clock rather than in response to a request.

Basic handler

ts
// Learn more: https://docs.val.town/vals/cron/export default async function (interval: Interval) {  // interval.lastRunAt: Date | undefined  console.log(interval);}

The file must have an export — export default for the handler.

Timezone

Cron expressions run in UTC. Convert any human-readable schedule (e.g. "9am Eastern") to UTC before writing the cron expression. Daylight savings is not handled — pick a UTC time that's close enough year-round.

The lastRunAt pattern

interval.lastRunAt is the timestamp of the previous successful run (or undefined on the first run). Use it to fetch only items created since the last run, instead of re-scanning everything:

ts
export default async function (interval: Interval) {  const since = interval.lastRunAt ?? new Date(Date.now() - 24 * 60 * 60 * 1000);  const newItems = await fetchItemsSince(since);  for (const item of newItems) {    await handle(item);  }}

This makes the val idempotent against missed runs and avoids reprocessing.

Reading and updating the schedule

  • read_interval_settings — fetch the current cron expression and active state of an interval file.
  • write_interval_settings — change the cron expression or pause/resume an interval.

When to skip a template

For simple scheduled jobs, create a new val with a single interval-type file directly — no template needed. Templates are for more complex shapes (dashboards, AI agents, webhook + UI combos).

Verifying changes

After editing an interval val, use run_file to invoke the handler manually instead of waiting for the next scheduled run.

Source and attribution

Source:val-town/pluginsinplugin/skills/cron-and-intervalsat commit2d3ec65

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal