Jobs

The clock

Make due jobs run, with the clock of your adapter or a cron service.

Nothing runs a job until the clock ticks. Each tick runs the due jobs one after another, up to 100. The framework adapters bring a clock, so on most hosts a job runs within a minute of its time:

HostClock
Nuxt, TanStack Start, tenonAdmin()A Nitro scheduled task, tenon:jobs, every minute
Astro on Node, and astro devA timer in the server process, every minute, from the first request on
Cloudflare with a Durable ObjectThe object's alarm. It wakes when a job is due
Vercel, other serverless hostsNone. Call the clock route from a cron service
  • The Nitro task needs a host that runs scheduled tasks, like Node, Bun, Deno or Cloudflare Cron Triggers. Nitro sets up the cron of the platform for you.
  • On Vercel, Nitro 3 (TanStack Start, standalone) turns the task into a Vercel Cron Job. Nitro 2 (Nuxt) does not, so the Nuxt task never runs there. The Nuxt module warns in a Vercel build unless jobs is false.
  • The Astro timer stops with the process. Jobs that came due in the meantime run on the first tick after the next start.
Vercel Hobby allows one cron job a day, and a deploy with a cron every minute fails. So the Vercel starters of npm create tenoncms set jobs: false. Call the clock route from an outside cron service, or, on the Pro plan, remove jobs: false (TanStack Start, standalone) or add the clock route to crons in vercel.json.

Turn the built-in clock off

Set jobs: false on the adapter:

export default defineConfig({
  integrations: [tenonCms({ jobs: false })],
});

Then run the jobs yourself, with the clock route or with cms.jobs.run() from your own timer:

const { ran, next } = await cms.jobs.run();

ran is how many jobs ran. next is when the next job is due, in epoch milliseconds, or null.

cms.jobs.run() exists only on the instance you import, and on its withDrafts() and withSession() copies. The cms in hooks and tasks has no run(), because a hook holds a transaction open, and on a database with one connection the tasks would wait on it forever.

The clock route

An outside clock can call /_tenon/jobs/run. The route exists once you set a secret:

tenon.config.ts
jobs: {
  secret: process.env.CRON_SECRET,
  tasks: { /* ... */ },
},
curl -H "Authorization: Bearer $CRON_SECRET" https://example.com/_tenon/jobs/run
# {"ran":2,"next":1767000000000}
  • The route takes GET and POST. Vercel Cron sends GET with Authorization: Bearer $CRON_SECRET, so it works as it is. Add the path under crons in vercel.json.
  • Any cron or uptime service that can send a header works too.
  • A missing or wrong token answers 401.
  • Vercel: the clock on Vercel.
  • Recurring jobs: cron entries that need the clock to tick often enough.
  • Webhooks: deliveries that wait for the clock too.