Skip to content

Commit 78e1be3

Browse files
committed
Adds boolean helpers section to the runs and realtime pages
1 parent 1b9c4bd commit 78e1be3

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

docs/realtime/overview.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ description: Using the Trigger.dev v3 realtime API
55
---
66

77
import RealtimeExamplesCards from "/snippets/realtime-examples-cards.mdx";
8+
import RunBooleanHelpers from "/snippets/run-boolean-helpers.mdx";
89

910
Trigger.dev Realtime is a set of APIs that allow you to subscribe to runs and get real-time updates on the run status. This is useful for monitoring runs, updating UIs, and building realtime dashboards.
1011

@@ -195,6 +196,23 @@ The run object returned by the async iterator has the following fields:
195196
Indicates whether this is a test run.
196197
</ParamField>
197198

199+
## Boolean helpers
200+
201+
Run objects returned from Realtime subscriptions include convenient boolean helper methods to check the run's status:
202+
203+
```ts
204+
import { runs } from "@trigger.dev/sdk";
205+
206+
for await (const run of runs.subscribeToRun("run_1234")) {
207+
if (run.isCompleted) {
208+
console.log("Run completed successfully!");
209+
break;
210+
}
211+
}
212+
```
213+
214+
<RunBooleanHelpers />
215+
198216
## Type-safety
199217

200218
You can infer the types of the run's payload and output by passing the type of the task to the `subscribeToRun` function. This will give you type-safe access to the run's payload and output.

docs/runs.mdx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: "Runs"
33
description: "Understanding the lifecycle of task run execution in Trigger.dev"
44
---
55

6+
import RunBooleanHelpers from "/snippets/run-boolean-helpers.mdx";
7+
68
In Trigger.dev, the concepts of runs and attempts are fundamental to understanding how tasks are executed and managed. This article explains these concepts in detail and provides insights into the various states a run can go through during its lifecycle.
79

810
## What are runs?
@@ -63,7 +65,7 @@ during execution (likely due to an Out of Memory error) and won’t be retried.
6365
<Icon icon="bug" iconType="solid" color="#E11D48" size={17} /> **System failure**: An unrecoverable system
6466
error has occurred.
6567

66-
<Icon icon="trash-can" iconType="solid" color="#878C99" size={17} /> **Expired**: The run's Time-to-Live
68+
<Icon icon="trash-can" iconType="solid" color="#878C99" size={17} /> **Expired**: The run's [Time-to-Live](#time-to-live-ttl)
6769
(TTL) has passed before it could start executing.
6870

6971
## Attempts
@@ -87,6 +89,35 @@ A run is considered finished when:
8789

8890
At this point, the run will have either an output (if successful) or an error (if failed).
8991

92+
## Boolean helpers
93+
94+
Run objects returned from the API and Realtime include convenient boolean helper methods to check the run's status:
95+
96+
```ts
97+
import { runs } from "@trigger.dev/sdk";
98+
99+
const run = await runs.retrieve("run_1234");
100+
101+
if (run.isCompleted) {
102+
console.log("Run completed successfully");
103+
}
104+
```
105+
106+
<RunBooleanHelpers />
107+
108+
These helpers are also available when subscribing to Realtime run updates:
109+
110+
```ts
111+
import { runs } from "@trigger.dev/sdk";
112+
113+
for await (const run of runs.subscribeToRun("run_1234")) {
114+
if (run.isCompleted) {
115+
console.log("Run completed successfully!");
116+
break;
117+
}
118+
}
119+
```
120+
90121
## Advanced run features
91122

92123
### Idempotency Keys
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- **`isQueued`**: Returns `true` when the status is `QUEUED`, `PENDING_VERSION`, or `DELAYED`
2+
- **`isExecuting`**: Returns `true` when the status is `EXECUTING` or `DEQUEUED`. These count against your concurrency limits.
3+
- **`isWaiting`**: Returns `true` when the status is `WAITING`. These do not count against your concurrency limits.
4+
- **`isCompleted`**: Returns `true` when the status is any of the completed statuses
5+
- **`isCanceled`**: Returns `true` when the status is `CANCELED`
6+
- **`isFailed`**: Returns `true` when the status is any of the failed statuses
7+
- **`isSuccess`**: Returns `true` when the status is `COMPLETED`

0 commit comments

Comments
 (0)