Schedules and table changes
Run code on a cron schedule or after rows of a table change.
Schedules
app.cron("0 9 * * 1", { name: "weekly-report", tz: "Asia/Ho_Chi_Minh" }, async (c) => {
// c.event = { kind: "cron", at, cron }
return { sent: true } // the return value is written to the log
})- Standard five-field cron expressions. The most frequent schedule is every 5 minutes.
- Up to 10 schedules per service.
Table changes
app.onChange("Tasks", ["add", "update", "delete"], { name: "tasks-changed" }, async (c) => {
const { id, name, op, rows } = c.event.table
const fresh = await c.var.think.store.list("Tasks", { where: { _id: rows[0] } })
})- Handlers run after the table changes, whoever made the change.
c.event.tableis{ id, name, op, rows }, whererowsis the list of row IDs. Read new values withstore.listorstore.sql.- Writes made by a table handler do not trigger the service again, to prevent loops.
- Up to 20 table handlers per service.
Tables written only through the service
app.owns("Tasks", …) prevents everyone else, including editors, HTML pages and MCP clients of invited people, from writing those tables directly; they must call your routes. The project owner, the service itself and the project's Functions can still write. Reads are not affected. Turning the service off, or deploying a version without owns, opens the tables again.