Skip to content

Commit 471c960

Browse files
authored
Some more queue docs changes for v4 (#2414)
1 parent 0ae59cf commit 471c960

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

docs/migrating-from-v3.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,17 @@ await myTask.trigger({ foo: "bar" }); // Will use the queue defined on the task
210210
await myTask2.trigger({ foo: "bar" }); // Will use the queue defined on the task
211211
```
212212

213+
If you're using `concurrencyKey` you can specify the `queue` and `concurrencyKey` like this:
214+
215+
```ts
216+
const handle = await generatePullRequest.trigger(data, {
217+
queue: "paid-users",
218+
concurrencyKey: data.userId,
219+
});
220+
```
221+
222+
For each unique value of `concurrencyKey`, a new queue will be created using the `concurrencyLimit` from the queue. This allows you to have a queue per user.
223+
213224
### Lifecycle hooks
214225

215226
We've changed the function signatures of the lifecycle hooks to be more consistent and easier to use, by unifying all the parameters into a single object that can be destructured.

docs/queue-concurrency.mdx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ concurrency limit of your environment.
1717
Each individual queue has a maximum concurrency limit equal to your environment's base concurrency limit. If you don't explicitly set a queue's concurrency limit, it will default to your environment's base concurrency limit.
1818

1919
<Note>
20-
Your environment has a base concurrency limit and a burstable limit (default burst factor of 2.0x the base limit). Individual queues are limited by the base concurrency limit, not the burstable limit. For example, if your base limit is 10, your environment can burst up to 20 concurrent runs, but any single queue can have at most 10 concurrent runs. If you're a paying customer you can request higher limits by [contacting us](https://www.trigger.dev/contact).
20+
Your environment has a base concurrency limit and a burstable limit (default burst factor of 2.0x
21+
the base limit). Individual queues are limited by the base concurrency limit, not the burstable
22+
limit. For example, if your base limit is 10, your environment can burst up to 20 concurrent runs,
23+
but any single queue can have at most 10 concurrent runs. If you're a paying customer you can
24+
request higher limits by [contacting us](https://www.trigger.dev/contact).
2125
</Note>
2226

2327
## Setting task concurrency
@@ -75,6 +79,11 @@ When you trigger a task you can override the concurrency limit. This is really u
7579
The task:
7680

7781
```ts /trigger/override-concurrency.ts
82+
const paidQueue = queue({
83+
name: "paid-users",
84+
concurrencyLimit: 10,
85+
});
86+
7887
export const generatePullRequest = task({
7988
id: "generate-pull-request",
8089
queue: {
@@ -98,12 +107,8 @@ export async function POST(request: Request) {
98107
if (data.branch === "main") {
99108
//trigger the task, with a different queue
100109
const handle = await generatePullRequest.trigger(data, {
101-
queue: {
102-
//the "main-branch" queue will have a concurrency limit of 10
103-
//this triggered run will use that queue
104-
name: "main-branch", // Make sure to change the queue name or the task concurrency limit will be updated
105-
concurrencyLimit: 10,
106-
},
110+
// Set the paid users queue
111+
queue: "paid-users",
107112
});
108113

109114
return Response.json(handle);
@@ -132,11 +137,7 @@ export async function POST(request: Request) {
132137
if (data.isFreeUser) {
133138
//free users can only have 1 PR generated at a time
134139
const handle = await generatePullRequest.trigger(data, {
135-
queue: {
136-
//every free user gets a queue with a concurrency limit of 1
137-
name: "free-users",
138-
concurrencyLimit: 1,
139-
},
140+
queue: "free-users",
140141
concurrencyKey: data.userId,
141142
});
142143

@@ -145,11 +146,7 @@ export async function POST(request: Request) {
145146
} else {
146147
//trigger the task, with a different queue
147148
const handle = await generatePullRequest.trigger(data, {
148-
queue: {
149-
//every paid user gets a queue with a concurrency limit of 10
150-
name: "paid-users",
151-
concurrencyLimit: 10,
152-
},
149+
queue: "paid-users",
153150
concurrencyKey: data.userId,
154151
});
155152

@@ -188,12 +185,14 @@ With our [task checkpoint system](/how-it-works#the-checkpoint-resume-system), t
188185
Concurrency is only released when a run reaches a waitpoint and is checkpointed. When a run is checkpointed, it transitions to the `WAITING` state and releases its concurrency slot back to both the queue and the environment, allowing other runs to execute or resume.
189186

190187
This means that:
188+
191189
- Only actively executing runs count towards concurrency limits
192190
- Runs in the `WAITING` state (checkpointed at waitpoints) do not consume concurrency slots
193191
- You can have more runs in the `WAITING` state than your queue's concurrency limit
194192
- When a waiting run resumes (e.g., when a subtask completes), it must re-acquire a concurrency slot
195193

196194
For example, if you have a queue with a `concurrencyLimit` of 1:
195+
197196
- You can only have exactly 1 run executing at a time
198197
- You may have multiple runs in the `WAITING` state that belong to that queue
199198
- When the executing run reaches a waitpoint and checkpoints, it releases its slot

0 commit comments

Comments
 (0)