Loading...
Loading...
Schedule periodic / recurring work in Encore.ts using `CronJob` from `encore.dev/cron`. Covers `every: "1h"` interval syntax and `schedule: "0 9 * * 1"` cron expressions.
npx skill4agent add encoredev/skills encore-cronCronJobapi(...)CronJobimport { CronJob } from "encore.dev/cron";
import { api } from "encore.dev/api";
// 1. The endpoint to call (typically internal: expose: false)
export const aggregateDailyOrders = api(
{ expose: false },
async (): Promise<void> => {
// Aggregation logic
}
);
// 2. Package-level cron declaration
const _ = new CronJob("aggregate-daily-orders", {
title: "Aggregate orders for the previous day",
schedule: "0 2 * * *", // 02:00 UTC every day
endpoint: aggregateDailyOrders,
});| Field | Example | Description |
|---|---|---|
| | Simple interval. Must divide 24h evenly — |
| | Standard cron expression (5 fields, UTC). |
| Cron | Meaning |
|---|---|
| Every hour, on the hour |
| Daily at 02:00 UTC |
| Weekly on Sunday at midnight UTC |
| 04:00 UTC on the 15th of each month |
encore runexpose: falsescheduleCronJobeveryscheduleencore-pubsub