Skip to content
25K
Console

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:

cron.ts
export default {
async scheduled() {
console.log("Running on a schedule");
},
};

Pass in a schedules and a worker that’ll be executed.

sst.config.ts
new sst.cloudflare.Cron("MyCronJob", {
worker: "cron.ts",
schedules: ["* * * * *"]
});

Customize the worker

sst.config.ts
new sst.cloudflare.Cron("MyCronJob", {
schedules: ["* * * * *"],
worker: {
handler: "cron.ts",
link: [bucket]
}
});

Constructor

new Cron(name, args, opts?)

Parameters

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?

Type Object

Transform how this component creates its underlying resources.

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

Type Object

The underlying resources this component creates.

nodes.trigger

Type Output<WorkerCronTrigger>

The Cloudflare Worker Cron Trigger.

nodes.worker

Type Output<WorkerScript>

The Cloudflare Worker.