The clock
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:
| Host | Clock |
|---|---|
Nuxt, TanStack Start, tenonAdmin() | A Nitro scheduled task, tenon:jobs, every minute |
Astro on Node, and astro dev | A timer in the server process, every minute, from the first request on |
| Cloudflare with a Durable Object | The object's alarm. It wakes when a job is due |
| Vercel, other serverless hosts | None. 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
jobsisfalse. - The Astro timer stops with the process. Jobs that came due in the meantime run on the first tick after the next start.
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 })],
});
export default defineNuxtConfig({
modules: ["tenoncms/nuxt"],
tenonCms: { jobs: false },
});
export default defineConfig({
plugins: [tanstackStart(), nitro(), viteReact(), tenonAdmin({ 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:
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
GETandPOST. Vercel Cron sendsGETwithAuthorization: Bearer $CRON_SECRET, so it works as it is. Add the path undercronsinvercel.json. - Any cron or uptime service that can send a header works too.
- A missing or wrong token answers
401.
Related resources
- 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.