Skip to content

Commit 9771b85

Browse files
aquivealgitbutler-client
authored andcommitted
docs: add documentation for rate limiting
Add a new guide for rate limiting tasks and update the introduction, task overview, and sidebar to include the new functionality. This allows users to control run execution frequency using static or dynamic keys.
1 parent 11ffb83 commit 9771b85

4 files changed

Lines changed: 31 additions & 1 deletion

File tree

docs/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
]
8383
},
8484
"queue-concurrency",
85+
"rate-limiting",
8586
"versioning",
8687
"machines",
8788
"idempotency",

docs/introduction.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ We provide everything you need to build and manage background tasks: a CLI and S
7474
<Card title="Concurrency & Queues" icon="line-height" href="/queue-concurrency" color="#D946EF">
7575
Configure what you want to happen when there is more than one run at a time.
7676
</Card>
77+
<Card title="Rate Limiting" icon="gauge-high" href="/rate-limiting" color="#F59E0B">
78+
Control how many runs can execute within a specific time window.
79+
</Card>
7780
<Card
7881
title="Wait for token (human-in-the-loop)"
7982
icon="hand"

docs/tasks/overview.mdx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ It's also worth mentioning that you can [retry a block of code](/errors-retrying
100100

101101
### `queue` options
102102

103-
Queues allow you to control the concurrency of your tasks. This allows you to have one-at-a-time execution and parallel executions. There are also more advanced techniques like having different concurrencies for different sets of your users. For more information read [the concurrency & queues guide](/queue-concurrency).
103+
Queues allow you to control the concurrency of your tasks. This allows you to have one-at-a-time execution and parallel executions. There are also more advanced techniques like having different concurrencies for different sets of your users. For more information read [the concurrency, queues & rate limiting guide](/queue-concurrency).
104104

105105
```ts /trigger/one-at-a-time.ts
106106
export const oneAtATime = task({
@@ -114,6 +114,31 @@ export const oneAtATime = task({
114114
});
115115
```
116116

117+
### `rateLimits` options
118+
119+
Rate limits allow you to control how many runs can execute within a specific time window. You can define both static and dynamic rate limits. For more information read [the rate limiting guide](/rate-limiting).
120+
121+
```ts /trigger/rate-limited.ts
122+
export const rateLimitedTask = task({
123+
id: "rate-limited-task",
124+
rateLimits: [
125+
{
126+
staticKey: "my-api",
127+
limit: 100,
128+
window: 60, // 100 runs per 60 seconds
129+
},
130+
{
131+
dynamicKey: "payload.userId",
132+
limit: 10,
133+
window: 60, // 10 runs per 60 seconds per user
134+
}
135+
],
136+
run: async (payload: any, { ctx }) => {
137+
//...
138+
},
139+
});
140+
```
141+
117142
### `machine` options
118143

119144
Some tasks require more vCPUs or GBs of RAM. You can specify these requirements in the `machine` field. For more information read [the machines guide](/machines).

docs/writing-tasks-introduction.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Before digging deeper into the details of writing tasks, you should read the [fu
1616
| [Errors & retrying](/errors-retrying) | How to deal with errors and write reliable tasks. |
1717
| [Wait](/wait) | Wait for periods of time or for external events to occur before continuing. |
1818
| [Concurrency & Queues](/queue-concurrency) | Configure what you want to happen when there is more than one run at a time. |
19+
| [Rate Limiting](/rate-limiting) | Control how many runs can execute within a specific time window. |
1920
| [Realtime notifications](/realtime/overview) | Send realtime notifications from your task that you can subscribe to from your backend or frontend. |
2021
| [Versioning](/versioning) | How versioning works. |
2122
| [Machines](/machines) | Configure the CPU and RAM of the machine your task runs on |

0 commit comments

Comments
 (0)