Files
triggerdotdev--trigger.dev/docs/realtime/subscribe-to-run.mdx
T
2024-10-29 13:57:02 +00:00

50 lines
1.2 KiB
Plaintext

---
title: runs.subscribeToRun
sidebarTitle: subscribeToRun
description: Subscribes to all changes to a run.
---
import RunObject from "/snippets/realtime/run-object.mdx";
<RequestExample>
```ts Example
import { runs } from "@trigger.dev/sdk/v3";
for await (const run of runs.subscribeToRun("run_1234")) {
console.log(run);
}
```
</RequestExample>
This function subscribes to all changes to a run. It returns an async iterator that yields the run object whenever the run is updated. The iterator will complete when the run is finished.
### Authentication
This function supports both server-side and client-side authentication. For server-side authentication, use your API key. For client-side authentication, you must generate a public access token with one of the following scopes:
- `read:runs`
- `read:runs:<runId>`
To generate a public access token, use the `auth.createPublicToken` function:
```ts
import { auth } from "@trigger.dev/sdk/v3";
// Somewhere in your backend code
const publicToken = await auth.createPublicToken({
scopes: {
read: {
runs: ["run_1234"],
},
},
});
```
### Response
The AsyncIterator yields an object with the following properties:
<RunObject />