Operations

Run work in the background, tell other services about changes, and keep your data safe.

Tenon runs inside your app, so it has no separate service to operate. The pages in operations cover what a running site needs beyond its content: work that runs outside a request, messages to people and other services, backups, and changes to the schema and to Tenon itself.

What to use

ToUseSee
Change or check data before it is storedA beforeChange hookHooks
Do slow work after a write, or on a scheduleA jobJobs
Tell another service that published content changedA webhookWebhooks
Send invites, password resets and your own mailemailEmail
Fill a new database, or run code on startseed, onInitLifecycle hooks
Report errors to a service like SentryafterErrorLifecycle hooks
Save all content, or move it to another databasetenon backup, cms.export()Backup and restore
Rename a field, or install a new version of TenonA deployUpgrades and schema changes

React to a change

Hooks, jobs, webhooks and email can all run after a write. They differ in when they run and what happens when they fail:

HookJobWebhookEmail
RunsDuring the writeAfter the commit, on a tickAfter the commit, on a tickAt once, when you call it
A failureRolls the write backRetriesRetriesThrows to the caller
A rollback of the writeUndoes the hook's writesRemoves the jobSends nothingCannot take the mail back
Needs the clockNoYesYesNo

As a rule:

  • Keep hooks fast. They hold the write's transaction open.
  • Move calls to other services into a job or a webhook. They run after the commit and retry.
  • Send mail that MUST wait for the commit from a job.

The clock

Jobs, webhooks and scheduled publishing run only when the clock ticks. With Astro on Node, Nuxt, TanStack Start, tenonAdmin() and Cloudflare, the adapters tick every minute or when a job is due. On Vercel and other serverless hosts, set up the clock route, or nothing runs.

  • The clock: the clock on each host.
  • Hooks: the order of every step in a write.
  • CLI: backups, restores, users and upgrades from the command line.