Skip to content

Commit ddeb9c4

Browse files
authored
docs: heartbeats, Bun version, troubleshooting, and preview-branch cleanup (#3026)
Doc updates: - new Heartbeats page (yield, progress, external updates) - Bun supported-version note - resource_exhausted troubleshooting with native builder link - GitHub Actions preview-branch example with closed trigger so branches archive when PRs close <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/triggerdotdev/trigger.dev/pull/3026" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end -->
1 parent 2feecec commit ddeb9c4

File tree

6 files changed

+84
-2
lines changed

6 files changed

+84
-2
lines changed

docs/deployment/preview-branches.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ This GitHub Action will:
7272

7373
1. Automatically create a preview branch for your Pull Request (if the branch doesn't already exist).
7474
2. Deploy the preview branch.
75-
3. Archive the preview branch when the Pull Request is merged/closed.
75+
3. Archive the preview branch when the Pull Request is merged/closed. This only works if your workflow runs on **closed** PRs (`types: [opened, synchronize, reopened, closed]`). If you omit `closed`, branches won't be archived automatically.
7676

7777
```yml .github/workflows/trigger-preview-branches.yml
7878
name: Deploy to Trigger.dev (preview branches)

docs/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"machines",
7171
"idempotency",
7272
"runs/max-duration",
73+
"runs/heartbeats",
7374
"tags",
7475
"runs/metadata",
7576
"tasks/streams",

docs/github-actions.mdx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,41 @@ jobs:
8383
8484
If you already have a GitHub action file, you can just add the final step "🚀 Deploy Trigger.dev" to your existing file.
8585
86+
## Preview branches
87+
88+
To deploy to preview branches from Pull Requests and have them archived when PRs are merged or closed, use a workflow that runs on `pull_request` with **all four types** including `closed`:
89+
90+
```yaml .github/workflows/trigger-preview-branches.yml
91+
name: Deploy to Trigger.dev (preview branches)
92+
93+
on:
94+
pull_request:
95+
types: [opened, synchronize, reopened, closed]
96+
97+
jobs:
98+
deploy-preview:
99+
runs-on: ubuntu-latest
100+
steps:
101+
- uses: actions/checkout@v4
102+
103+
- name: Use Node.js 20.x
104+
uses: actions/setup-node@v4
105+
with:
106+
node-version: "20.x"
107+
108+
- name: Install dependencies
109+
run: npm install
110+
111+
- name: Deploy preview branch
112+
run: npx trigger.dev@latest deploy --env preview
113+
env:
114+
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
115+
```
116+
117+
<Note>
118+
**Include `closed`** in the `pull_request.types` list. Without it, preview branches won't be archived when PRs are merged or closed, and you may hit the limit on active preview branches. See [Preview branches](/deployment/preview-branches#preview-branches-with-github-actions-recommended) for more details.
119+
</Note>
120+
86121
## Creating a Personal Access Token
87122

88123
<Steps>

docs/guides/frameworks/bun.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import CliViewRunStep from "/snippets/step-view-run.mdx";
1414
Bun will still be used to execute your tasks, even in the `dev` environment.
1515
</Warning>
1616

17+
<Note>
18+
**Supported Bun version:** Deployed tasks run on Bun 1.3.3. For local development, use Bun 1.3.x for compatibility.
19+
</Note>
20+
1721
<Prerequisites framework="Bun" />
1822

1923
## Known issues

docs/runs/heartbeats.mdx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: "Heartbeats"
3+
sidebarTitle: "Heartbeats"
4+
description: "Keep long-running or CPU-heavy tasks from being marked as stalled."
5+
---
6+
7+
We send a heartbeat from your task to the platform every 30 seconds. If we don't receive a heartbeat within 5 minutes, we mark the run as stalled and stop it with a `TASK_RUN_STALLED_EXECUTING` error.
8+
9+
Code that blocks the event loop for too long (for example, a tight loop doing synchronous work on a large dataset) can prevent heartbeats from being sent. In that case, use `heartbeats.yield()` inside the loop so the runtime can yield to the event loop and send a heartbeat. You can call it every iteration; the implementation only yields when needed.
10+
11+
```ts
12+
import { task, heartbeats } from "@trigger.dev/sdk";
13+
14+
export const processLargeDataset = task({
15+
id: "process-large-dataset",
16+
run: async (payload: { items: string[] }) => {
17+
for (const row of payload.items) {
18+
await heartbeats.yield();
19+
processRow(row);
20+
}
21+
return { processed: payload.items.length };
22+
},
23+
});
24+
25+
function processRow(row: string) {
26+
// synchronous CPU-heavy work
27+
}
28+
```
29+
30+
If you see `TASK_RUN_STALLED_EXECUTING`, see [Task run stalled executing](/troubleshooting#task-run-stalled-executing) in the troubleshooting guide.
31+
32+
## Sending progress to Trigger.dev
33+
34+
To stream progress or status updates to the dashboard and your app, use [run metadata](/runs/metadata). Call `metadata.set()` (or `metadata.append()`) as the task runs. The dashboard and [Realtime](/realtime) (including `runs.subscribeToRun` and the React hooks) receive those updates as they happen. See [Progress monitoring](/realtime/backend/subscribe#progress-monitoring) for a full example.
35+
36+
## Sending updates to your own system
37+
38+
Trigger.dev doesn’t push run updates to external services. To send progress or heartbeats to your own backend (for example Supabase Realtime), call your API or client from inside the task when you want to emit an update—e.g. in the same loop where you call `heartbeats.yield()` or `metadata.set()`. Use whatever your stack supports: HTTP, the Supabase client, or another SDK.

docs/troubleshooting.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ This happens because Docker Desktop left behind a config file that's still tryin
7373

7474
Usually there will be some useful guidance below this message. If you can't figure out what's going wrong then join [our Discord](https://trigger.dev/discord) and create a Help forum post with a link to your deployment.
7575

76+
### `resource_exhausted`
77+
78+
If you see a `resource_exhausted` error during deploy, the build may have hit resource limits on our build infrastructure. Try our [native builder](https://trigger.dev/changelog/deployments-with-native-builds).
79+
7680
### `No loader is configured for ".node" files`
7781

7882
This happens because `.node` files are native code and can't be bundled like other packages. To fix this, add your package to [`build.external`](/config/config-file#external) in the `trigger.config.ts` file like this:
@@ -175,7 +179,7 @@ The most common situation this happens is if you're using `Promise.all` around s
175179

176180
Make sure that you always use `await` when you call `trigger`, `triggerAndWait`, `batchTrigger`, and `batchTriggerAndWait`. If you don't then it's likely the task(s) won't be triggered because the calling function process can be terminated before the networks calls are sent.
177181

178-
### `COULD_NOT_FIND_EXECUTOR`
182+
### `COULD_NOT_FIND_EXECUTOR`
179183

180184
If you see a `COULD_NOT_FIND_EXECUTOR` error when triggering a task, it may be caused by dynamically importing the child task. When tasks are dynamically imported, the executor may not be properly registered.
181185

0 commit comments

Comments
 (0)