Scheduled publishing
Editors can plan a publish or an unpublish for a later time. Tenon runs each schedule as a built-in job, so it needs no setup beyond one option, as long as the clock on your host ticks.
tenonAdmin() with Nitro tick every minute. On other hosts, set up the clock yourself, or nothing is published.Turn on scheduling
Set schedule: true on a collection or global:
export const posts = defineCollection({
schedule: true,
fields: {
// ...
},
});
schedule needs drafts. With drafts: false, Tenon throws at startup.
Schedule in the admin
Open the menu next to Publish and choose Schedule…. Pick the action, the date and time and, in a localized entry, the languages.
- The dialog lists the upcoming schedules. Cancel schedule removes one.
- A time in the past asks first, then publishes or unpublishes right away.
- While a publish is scheduled, the document shows a notice, and its draft is locked.
Schedule from code
cms.schedule() plans a publish or an unpublish of a document, cms.scheduleGlobal() of a global:
await cms.schedule("posts", post.id, { action: "publish", at: "2027-01-01T09:00:00Z" });
await cms.schedule("posts", post.id, { action: "unpublish", at: new Date("2027-02-01") });
await cms.scheduleGlobal("settings", { action: "publish", at: Date.now() + 3_600_000 });
at.localized ignore it.Both return the id of the job. cms.schedule() returns undefined for a document that does not exist. The client has the same client.schedule() and client.scheduleGlobal().
Rules
- A scheduled publish locks the draft until it runs, so it publishes what you scheduled. Cancel the schedule to edit the draft again.
- A publish needs a draft: pending changes, or a document that was never published.
- A new schedule for the same action and language replaces the queued one.
- Scheduling needs the
updaterule of the document. The job runs as the server, so the rule is not checked again when it fires.
The built-in job
A schedule is a job of the built-in task tenon:publish or tenon:unpublish. It shows on the Jobs page like any other job.
- The job publishes as the server. The publish records no user.
- When the document is gone by then, the job ends as done, with the result
missing. - When the publish fails, for example because the schema changed and the draft no longer validates, the job retries and then shows under Failed.
- An editor who may update the document sees and cancels its schedule in the Schedule dialog. They do not need access to the Jobs page.
Related resources
- Writing and drafts: publish, unpublish and discard.
- The clock: what makes a schedule run on your host.
- Access control: the
updaterule.