Files
triggerdotdev--trigger.dev/docs/sdk/crontrigger.mdx
T
2023-09-08 11:52:51 +01:00

72 lines
1.6 KiB
Plaintext

---
title: "cronTrigger()"
description: "`cronTrigger()` is set as a [Job's trigger](/docs/sdk/job) to trigger a Job on a recurring schedule using a CRON expression."
---
## Development
<Snippet file="scheduled-dev-warning.mdx" />
## CRON expressions
CRON expressions are strings that define when something should happen.
Some examples:
- `"0 0 * * *"`: will run the Job every day at 12:00am UTC.
- `"30 14 * * 1"`: will run the Job every Monday at 2:30pm UTC.
A useful tool when writing CRON expressions is [crontab guru](https://crontab.guru).
## Parameters
<ResponseField name="options" type="object" required>
<Expandable title="options" defaultOpen>
<ResponseField name="cron" type="string" required>
A CRON expression that defines the schedule. Note that the timezone used is always UTC.
</ResponseField>
</Expandable>
</ResponseField>
<RequestExample>
```typescript 9am UTC everyday
client.defineJob({
id: "scheduled-job-1",
name: "Scheduled Job 1",
version: "0.1.1",
// 9am every day
trigger: cronTrigger({
cron: "0 9 * * *",
}),
run: async (payload, io, ctx) => {
await io.logger.info("Received the scheduled event", {
payload,
});
return { foo: "bar" };
},
});
```
```typescript First day of month
client.defineJob({
id: "scheduled-job-2",
name: "Scheduled Job 2",
version: "0.1.1",
// The first day of the month at 2am UTC
trigger: cronTrigger({
cron: "0 2 1 * *",
}),
run: async (payload, io, ctx) => {
await io.logger.info("Received the scheduled event", {
payload,
});
return { foo: "bar" };
},
});
```
</RequestExample>