Cron Jobs
Any file ending in .cron.ts is registered as a scheduled job. Exports:
schedule— standard 5-field cron syntax, in UTC (day-of-week: 0 or 7 = Sunday, 1 = Monday).default— an async function. Does not return a response.
A run that throws is retried up to 3 attempts (30s, 60s later), so keep jobs idempotent. Jobs can be paused or run on demand from the workspace Cron view.
// app/orders/cleanup-stale.cron.ts — DB access through the repository, like handlers
import { cancelStalePending } from "./repository";
// repository.ts: export async function cancelStalePending(before: number) {
// await db.update(orders).set({ status: "cancelled" }).where(and(eq(orders.status, "pending"), lt(orders.createdAt, before)));
// }
export const schedule = "0 * * * *"; // every hour
export default async function () {
await cancelStalePending(Date.now() - 24 * 60 * 60 * 1000); // idempotent: re-running changes nothing new
}Cron syntax cheat sheet:
| Expression | Meaning |
|---|---|
* * * * * | Every minute |
0 * * * * | Every hour |
0 0 * * * | Every day at midnight |
0 0 * * 0 | Every Sunday at midnight |
*/15 * * * * | Every 15 minutes |
Last updated on