Skip to content

Commit a38886a

Browse files
committed
Add wait for token docs and improve upgrade guide
1 parent f8e3a40 commit a38886a

File tree

3 files changed

+461
-18
lines changed

3 files changed

+461
-18
lines changed

docs/snippets/upgrade-to-v4-note.mdx

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<Note>
2+
This feature is only available in the v4 beta. To upgrade to v4, see the [upgrade to v4
3+
docs](/upgrade-to-v4).
4+
</Note>

docs/upgrade-to-v4.mdx

+26-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: "What's new in v4, how to upgrade, and breaking changes."
55

66
## What's new in v4?
77

8-
Link to blog post here
8+
[Read our blog post](https://trigger.dev/blog/v4-beta-launch) for an overview of the new features.
99

1010
### Wait tokens
1111

@@ -36,11 +36,15 @@ await wait.completeToken(tokenId, {
3636
You can wait for the token using the token ID:
3737

3838
```ts
39+
type ApprovalToken = {
40+
status: "approved" | "rejected";
41+
};
42+
3943
// Inside a task
40-
const result = await wait.forToken(tokenId);
44+
const result = await wait.forToken<ApprovalToken>(tokenId);
4145

4246
if (result.ok) {
43-
console.log("Token completed", result.output);
47+
console.log("Token completed", result.output.status); // "approved" or "rejected"
4448
} else {
4549
console.log("Token timed out", result.error);
4650
}
@@ -51,7 +55,7 @@ if (result.ok) {
5155
You can now pass an idempotency key to any wait function, allowing you to skip waits if the same idempotency key is used again. This can be useful if you want to skip waits when retrying a task, for example:
5256

5357
```ts
54-
// Specify the idempotency key and TTL when creating a the token
58+
// Specify the idempotency key and TTL when creating a wait token
5559
const token = await wait.createToken({
5660
idempotencyKey: "my-idempotency-key",
5761
idempotencyKeyTTL: "1h",
@@ -80,7 +84,7 @@ You can now specify a priority when triggering a task. This allows you to priori
8084
await task.trigger({ foo: "bar" }, { priority: 1 });
8185
```
8286

83-
The priority value is a time duration in seconds, which offsets the timestamp of the run in the queue. If you specify a priority of `10`, the run will have over runs with a priority of `0` that were triggered within the last 10 seconds. A more concrete example:
87+
The priority value is a time duration in seconds, which offsets the timestamp of the run in the queue. If you specify a priority of `10`, the run will win over runs with a priority of `0` that were triggered within the last 10 seconds. A more concrete example:
8488

8589
```ts
8690
// Triggered at 12:00:00, into a queue with a large number of queued runs
@@ -93,7 +97,7 @@ In this case, the second run will be executed first, because it's priority moved
9397

9498
<Note>
9599
We purposefully chose to use a time duration as the priority value instead of specifying priority
96-
levels, because priority levels can cause "level starvation" where lower priortity runs are never
100+
levels, because priority levels can cause "level starvation" where lower priority runs are never
97101
executed because there are always higher priority runs in the queue.
98102
</Note>
99103

@@ -440,38 +444,38 @@ See the [AI SDK tool execution options docs](https://sdk.vercel.ai/docs/ai-sdk-c
440444

441445
## Installation
442446

443-
To opt-in to using v4, you will need to update your dependencies to the latest version of the `v4` tag.
447+
To opt-in to using v4, you will need to update your dependencies to the latest version of the `v4-beta` tag.
444448

445449
<CodeGroup>
446450

447451
```bash npm
448-
npm add @trigger.dev/sdk@v4
452+
npm add @trigger.dev/sdk@v4-beta
449453
```
450454

451455
```bash yarn
452-
yarn add @trigger.dev/sdk@v4
456+
yarn add @trigger.dev/sdk@v4-beta
453457
```
454458

455459
```bash pnpm
456-
pnpm add @trigger.dev/sdk@v4
460+
pnpm add @trigger.dev/sdk@v4-beta
457461
```
458462

459463
</CodeGroup>
460464

461-
You'll also need to use the `v4` version of the `trigger.dev` CLI package:
465+
You'll also need to use the `v4-beta` version of the `trigger.dev` CLI package:
462466

463467
<CodeGroup>
464468

465469
```bash npx
466-
npx trigger.dev@v4 dev
470+
npx trigger.dev@v4-beta dev
467471
```
468472

469473
```bash yarn
470-
yarn dlx trigger.dev@v4 dev
474+
yarn dlx trigger.dev@v4-beta dev
471475
```
472476

473477
```bash pnpm
474-
pnpm dlx trigger.dev@v4 dev
478+
pnpm dlx trigger.dev@v4-beta dev
475479
```
476480

477481
</CodeGroup>
@@ -481,7 +485,7 @@ Or you could install the CLI into your `devDependencies` and then use the `trigg
481485
```json package.json
482486
{
483487
"devDependencies": {
484-
"trigger.dev": "v4"
488+
"trigger.dev": "v4-beta"
485489
},
486490
"scripts": {
487491
"dev": "trigger dev"
@@ -644,14 +648,20 @@ You can also now control whether concurrency is released when performing a wait:
644648
await wait.for({ seconds: 10 }, { releaseConcurrency: false });
645649
```
646650

647-
The new default behavior allows you to ensure that you can control the number of executing & waiting runs on a queue, and guarentee runs will resume once they are meant to be resumed.
651+
The new default behavior allows you to ensure that you can control the number of executing & waiting runs on a queue, and guarantee runs will resume once they are meant to be resumed.
648652

649653
<Note>
650654
If you do choose to release concurrency on waits, be aware that it's possible a resume is delayed
651655
if the concurrency that was released is not available at the time the wait completes. In this
652656
case, the run will go back into the queue and will resume once concurrency becomes available.
653657
</Note>
654658

659+
This new behavior effects all the wait functions:
660+
661+
- Wait for duration (e.g. `wait.for({ seconds: 10 })`)
662+
- Wait for a child task to complete (e.g. `myTask.triggerAndWait()`, `myTask.batchTriggerAndWait([...])`)
663+
- Wait for a token to complete (e.g. `wait.forToken(tokenId)`)
664+
655665
### Lifecycle hooks
656666

657667
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.

0 commit comments

Comments
 (0)