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

50 lines
1.3 KiB
Plaintext

---
title: runs.subscribeToRunsWithTag
sidebarTitle: subscribeToRunsWithTag
description: Subscribes to all changes to runs with a specific tag.
---
import RunObject from "/snippets/realtime/run-object.mdx";
<RequestExample>
```ts Example
import { runs } from "@trigger.dev/sdk/v3";
for await (const run of runs.subscribeToRunsWithTag("user:1234")) {
console.log(run);
}
```
</RequestExample>
This function subscribes to all changes to runs with a specific tag. It returns an async iterator that yields the run object whenever a run with the specified tag is updated. This iterator will never complete, so you must manually break out of the loop when you no longer want to receive updates.
### 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:tags:<tagName>`
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: {
tags: ["user:1234"],
},
},
});
```
### Response
The AsyncIterator yields an object with the following properties:
<RunObject />