Files
triggerdotdev--trigger.dev/docs/sdk/intervaltrigger.mdx
T

52 lines
1.6 KiB
Plaintext

---
title: "intervalTrigger()"
description: "`intervalTrigger()` is set as a [Job's trigger](/sdk/job) to trigger a Job at a recurring interval."
---
## Development
<Snippet file="scheduled-dev-warning.mdx" />
## Defining an interval
Intervals are set with a number of seconds. There are some important considerations:
- The Job will first run the specified number of seconds after it has first connected to an [Environment](/documentation/concepts/environments-endpoints). This will happen when you first [deploy](/documentation/guides/deployment) that Job.
- The minimum interval is 20 seconds (any input less than this it will default to 20).
- The maximum interval is 2_592_000 seconds (30 days), if you pass more than this it will trigger every 30 days.
If you wish to Run a Job at an exact time or less frequently than once pr day you should use a [cronTrigger()](/sdk/crontrigger) instead.
## Parameters
<ResponseField name="options" type="object" required>
<Expandable title="options" defaultOpen>
<ResponseField name="seconds" type="number" required>
The number of seconds for the interval. Min = 60, Max = 2_592_000 (30 days)
</ResponseField>
</Expandable>
</ResponseField>
<RequestExample>
```typescript Every 5 minutes
client.defineJob({
id: "scheduled-job-1",
name: "Scheduled Job 1",
version: "0.1.1",
// Every 5 minutes
trigger: intervalTrigger({
seconds: 60 * 5,
}),
run: async (payload, io, ctx) => {
await io.logger.info("Received the scheduled event", {
payload,
});
return { foo: "bar" };
},
});
```
</RequestExample>