*.cron.ts
Each *.cron.ts file is a job manh.run runs on a schedule, with nobody opening the app, written as a 5-field cron expression in UTC.
app/orders/
├── repository.ts
├── cancel-stale.cron.ts # job "cancel-stale"
└── daily-digest.cron.ts # job "daily-digest"What it does
The file name without .cron.ts is the job name. The file can live in any folder, usually next to the repository.ts of the resource it works on. A job calls repository functions like a handler does, so each business rule lives in one place.
Exports
schedule: a 5-field cron string in UTC. Vietnam time minus 7: 08:00 daily is"0 1 * * *".default: anasyncfunction with no arguments. It returns no response.
Example
app/orders/daily-digest.cron.ts
import { email } from "manh/email";
import { ordersSince } from "./repository";
export const schedule = "0 1 * * *"; // 08:00 Vietnam time
export default async function () {
const recent = await ordersSince(Date.now() - 24 * 3600 * 1000);
await email({
to: "owner@example.com",
subject: `${recent.length} orders yesterday`,
html: `<meta charset="utf-8"><p>${recent.length} new orders yesterday.</p>`,
});
}Good to know
- The shortest interval is 1 minute. An app has at most 20 distinct schedules; several jobs can share one.
- Each run gets 30 seconds of CPU. A failed run is retried, up to 3 attempts in total. While a run is still going, the next tick is skipped.
- Because runs repeat, a job must be safe to run twice: handle only unprocessed rows and mark them when done.
- Jobs skip
middleware.tsand have nocand no user. Pass what the repository needs explicitly. - Day of week: 0 or 7 is Sunday, 1 is Monday. When both day of month and day of week are set, either match fires the job.
- Pause a job or run it now under Operations › Cron in the project. The agent can do the same over MCP.
Next steps
- Scheduled jobs — change the time, handle only new rows, re-run safely.
- *.job.ts — move a job’s heavy work to the background so it stays under 30 s of CPU.
- Email, AI, file storage — send a report by e-mail from a job.
Last updated