Cron
The Cron component lets you add cron jobs to your app using Cloudflare.
It uses Cloudflare Cron Triggers.
Minimal example
Create a worker file that exposes a scheduled handler:
export default { async scheduled() { console.log("Running on a schedule"); },};Pass in a schedules and a worker that’ll be executed.
new sst.cloudflare.Cron("MyCronJob", { worker: "cron.ts", schedules: ["* * * * *"]});Customize the worker
new sst.cloudflare.Cron("MyCronJob", { schedules: ["* * * * *"], worker: { handler: "cron.ts", link: [bucket] }});Constructor
new Cron(name, args, opts?)Parameters
-
namestring -
argsCronArgs -
opts?ComponentResourceOptions
CronArgs
schedules
Type Input<string[]>
The schedule for the cron job.
You can use a cron expression.
{ schedules: ["* * * * *"] // schedules: ["*/30 * * * *"] // schedules: ["45 * * * *"] // schedules: ["0 17 * * sun"] // schedules: ["10 7 * * mon-fri"] // schedules: ["0 15 1 * *"] // schedules: ["59 23 LW * *"]}transform?
transform.trigger?
Type WorkerCronTriggerArgs | (args: WorkerCronTriggerArgs, opts: ComponentResourceOptions, name: string) => void
Transform the Worker Cron Trigger resource.
worker?
Type Input<string | WorkerArgs>
The worker that’ll be executed when the cron job runs.
{ worker: "src/cron.ts"}You can pass in the full worker props.
{ worker: { handler: "src/cron.ts", link: [bucket] }}Properties
nodes
nodes.trigger
Type Output<WorkerCronTrigger>
The Cloudflare Worker Cron Trigger.
nodes.worker
Type Output<WorkerScript>
The Cloudflare Worker.