Skip to content

Commit 575dffb

Browse files
committed
Merge remote-tracking branch 'origin/main' into onboarding-question
2 parents 96578bb + 1c80a74 commit 575dffb

File tree

7 files changed

+76
-57
lines changed

7 files changed

+76
-57
lines changed

apps/coordinator/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ class TaskCoordinator {
906906

907907
const ack = await this.#platformSocket?.sendWithAck("CHECKPOINT_CREATED", {
908908
version: "v1",
909+
runId: socket.data.runId,
909910
attemptFriendlyId: message.attemptFriendlyId,
910911
docker: checkpoint.docker,
911912
location: checkpoint.location,
@@ -986,6 +987,7 @@ class TaskCoordinator {
986987

987988
const ack = await this.#platformSocket?.sendWithAck("CHECKPOINT_CREATED", {
988989
version: "v1",
990+
runId: socket.data.runId,
989991
attemptFriendlyId: message.attemptFriendlyId,
990992
docker: checkpoint.docker,
991993
location: checkpoint.location,
@@ -1066,6 +1068,7 @@ class TaskCoordinator {
10661068

10671069
const ack = await this.#platformSocket?.sendWithAck("CHECKPOINT_CREATED", {
10681070
version: "v1",
1071+
runId: socket.data.runId,
10691072
attemptFriendlyId: message.attemptFriendlyId,
10701073
docker: checkpoint.docker,
10711074
location: checkpoint.location,

apps/webapp/app/v3/services/createCheckpoint.server.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class CreateCheckpointService extends BaseService {
5050
});
5151

5252
if (!attempt) {
53-
logger.error("Attempt not found", { attemptFriendlyId: params.attemptFriendlyId });
53+
logger.error("Attempt not found", params);
5454

5555
return {
5656
success: false,
@@ -70,6 +70,7 @@ export class CreateCheckpointService extends BaseService {
7070
id: attempt.taskRunId,
7171
status: attempt.taskRun.status,
7272
},
73+
params,
7374
});
7475

7576
return {
@@ -84,6 +85,7 @@ export class CreateCheckpointService extends BaseService {
8485
logger.error("Missing deployment or image ref", {
8586
attemptId: attempt.id,
8687
workerId: attempt.backgroundWorker.id,
88+
params,
8789
});
8890

8991
return {
@@ -170,6 +172,7 @@ export class CreateCheckpointService extends BaseService {
170172
taskRunId: attempt.taskRunId,
171173
type: "WAIT_FOR_TASK",
172174
reason,
175+
params,
173176
});
174177
await marqs?.cancelHeartbeat(attempt.taskRunId);
175178

@@ -182,6 +185,7 @@ export class CreateCheckpointService extends BaseService {
182185
if (!childRun) {
183186
logger.error("CreateCheckpointService: WAIT_FOR_TASK child run not found", {
184187
friendlyId: reason.friendlyId,
188+
params,
185189
});
186190

187191
return {
@@ -201,13 +205,15 @@ export class CreateCheckpointService extends BaseService {
201205
childRun,
202206
attempt,
203207
checkpointEvent,
208+
params,
204209
});
205210
} else {
206211
logger.error("CreateCheckpointService: Failed to resume dependent parents", {
207212
result,
208213
childRun,
209214
attempt,
210215
checkpointEvent,
216+
params,
211217
});
212218
}
213219

@@ -233,6 +239,7 @@ export class CreateCheckpointService extends BaseService {
233239
attemptId: attempt.id,
234240
taskRunId: attempt.taskRunId,
235241
type: "WAIT_FOR_BATCH",
242+
params,
236243
});
237244
await marqs?.cancelHeartbeat(attempt.taskRunId);
238245

@@ -248,6 +255,7 @@ export class CreateCheckpointService extends BaseService {
248255
if (!batchRun) {
249256
logger.error("CreateCheckpointService: Batch not found", {
250257
friendlyId: reason.batchFriendlyId,
258+
params,
251259
});
252260

253261
return {
@@ -297,6 +305,7 @@ export class CreateCheckpointService extends BaseService {
297305
logger.error("No checkpoint event", {
298306
attemptId: attempt.id,
299307
checkpointId: checkpoint.id,
308+
params,
300309
});
301310
await marqs?.acknowledgeMessage(attempt.taskRunId);
302311

docs/guides/examples/ffmpeg-video-processing.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ description: "These examples show you how to process videos in various ways usin
66

77
import LocalDevelopment from "/snippets/local-development-extensions.mdx";
88

9-
## Adding the FFmpeg build extension
9+
## Prerequisites
10+
11+
- A project with [Trigger.dev initialized](/quick-start)
12+
- [FFmpeg](https://www.ffmpeg.org/download.html) installed on your machine
13+
14+
### Adding the FFmpeg build extension
1015

1116
To use these example tasks, you'll first need to add our FFmpeg extension to your project configuration like this:
1217

docs/guides/examples/puppeteer.mdx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ description: "These examples demonstrate how to use Puppeteer with Trigger.dev."
77
import LocalDevelopment from "/snippets/local-development-extensions.mdx";
88
import ScrapingWarning from "/snippets/web-scraping-warning.mdx";
99

10+
## Prerequisites
11+
12+
- A project with [Trigger.dev initialized](/quick-start)
13+
- [Puppeteer](https://pptr.dev/guides/installation) installed on your machine
14+
1015
## Overview
1116

1217
There are 3 example tasks to follow on this page:
@@ -15,7 +20,7 @@ There are 3 example tasks to follow on this page:
1520
2. [Generate a PDF from a web page](/guides/examples/puppeteer#generate-a-pdf-from-a-web-page)
1621
3. [Scrape content from a web page](/guides/examples/puppeteer#scrape-content-from-a-web-page)
1722

18-
<ScrapingWarning/>
23+
<ScrapingWarning />
1924

2025
## Build configurations
2126

@@ -133,7 +138,6 @@ export const puppeteerWebpageToPDF = task({
133138
return { pdfUrl: s3Url };
134139
},
135140
});
136-
137141
```
138142

139143
### Testing your task
@@ -146,9 +150,10 @@ There's no payload required for this task so you can just click "Run test" from
146150

147151
In this example we use [Puppeteer](https://pptr.dev/) with a [BrowserBase](https://www.browserbase.com/) proxy to scrape the GitHub stars count from the [Trigger.dev](https://trigger.dev) landing page and log it out. See [this list](/guides/examples/puppeteer#proxying) for more proxying services we recommend.
148152

149-
<Note>
150-
When web scraping, you MUST use the technique below which uses a proxy with Puppeteer. Direct scraping without using `browserWSEndpoint` is prohibited and will result in account suspension.
151-
</Note>
153+
<Warning>
154+
When web scraping, you MUST use the technique below which uses a proxy with Puppeteer. Direct
155+
scraping without using `browserWSEndpoint` is prohibited and will result in account suspension.
156+
</Warning>
152157

153158
### Task code
154159

@@ -209,4 +214,4 @@ Here are a list of proxy services we recommend:
209214
- [Browserless](https://browserless.io/)
210215
- [Oxylabs](https://oxylabs.io/)
211216
- [ScrapingBee](https://scrapingbee.com/)
212-
- [Smartproxy](https://smartproxy.com/)
217+
- [Smartproxy](https://smartproxy.com/)

docs/guides/examples/sharp-image-processing.mdx

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ import LocalDevelopment from "/snippets/local-development-extensions.mdx";
88

99
## Overview
1010

11-
This task optimizes and watermarks an image using the Sharp library, and then uploads the processed image to R2 storage.
11+
This task processes and watermarks an image using the Sharp library, and then uploads it to R2 storage.
1212

13-
## Adding build configurations
13+
## Prerequisites
14+
15+
- A project with [Trigger.dev initialized](/quick-start)
16+
- The [Sharp](https://sharp.pixelplumbing.com/install) library installed on your machine
17+
- An R2-compatible object storage service, such as [Cloudflare R2](https://developers.cloudflare.com/r2)
18+
19+
## Adding the build configuration
1420

1521
To use this example, you'll first need to add these build settings to your `trigger.config.ts` file:
1622

@@ -34,22 +40,22 @@ export default defineConfig({
3440

3541
## Key features
3642

37-
- Resizes and rotates an image
38-
- Adds a watermark to the image
39-
- Uploads the processed image to R2 storage
43+
- Resizes a JPEG image to 800x800 pixels
44+
- Adds a watermark to the image, positioned in the bottom-right corner, using a PNG image
45+
- Uploads the processed image to R2 storage
4046

4147
## Task code
4248

4349
```ts trigger/sharp-image-processing.ts
44-
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
50+
import { S3Client } from "@aws-sdk/client-s3";
51+
import { Upload } from "@aws-sdk/lib-storage";
4552
import { logger, task } from "@trigger.dev/sdk/v3";
4653
import fs from "fs/promises";
47-
import fetch from "node-fetch";
4854
import os from "os";
4955
import path from "path";
5056
import sharp from "sharp";
5157

52-
// Initialize R2 client
58+
// Initialize R2 client using your R2 account details
5359
const r2Client = new S3Client({
5460
region: "auto",
5561
endpoint: process.env.R2_ENDPOINT,
@@ -61,63 +67,51 @@ const r2Client = new S3Client({
6167

6268
export const sharpProcessImage = task({
6369
id: "sharp-process-image",
70+
retry: { maxAttempts: 1 },
6471
run: async (payload: { imageUrl: string; watermarkUrl: string }) => {
6572
const { imageUrl, watermarkUrl } = payload;
73+
const outputPath = path.join(os.tmpdir(), `output_${Date.now()}.jpg`);
6674

67-
// Generate temporary and output file names
68-
const tempDirectory = os.tmpdir();
69-
const outputPath = path.join(tempDirectory, `output_${Date.now()}.jpg`);
70-
71-
// Fetch the image and watermark
7275
const [imageResponse, watermarkResponse] = await Promise.all([
7376
fetch(imageUrl),
7477
fetch(watermarkUrl),
7578
]);
7679
const imageBuffer = await imageResponse.arrayBuffer();
7780
const watermarkBuffer = await watermarkResponse.arrayBuffer();
7881

79-
// Optimize the image using Sharp
8082
await sharp(Buffer.from(imageBuffer))
81-
.rotate(90) // Rotate the image by 90 degrees
82-
.resize(800, 600) // Resize the image to 800x600
83+
.resize(800, 800) // Resize the image to 800x800px
8384
.composite([
8485
{
8586
input: Buffer.from(watermarkBuffer),
8687
gravity: "southeast", // Position the watermark in the bottom-right corner
8788
},
8889
])
89-
.toFormat("jpeg")
90-
.toFile(outputPath);
91-
92-
// Log the output file path
93-
logger.log(`Optimized image saved at: ${outputPath}`);
94-
95-
// Read the optimized image file
96-
const optimizedImageBuffer = await fs.readFile(outputPath);
97-
98-
// Upload the optimized image to R2, replacing slashes with underscores
99-
const r2Key = `processed-images/${path.basename(outputPath)}`;
100-
101-
const uploadParams = {
102-
Bucket: process.env.R2_BUCKET,
103-
Key: r2Key,
104-
Body: optimizedImageBuffer,
105-
};
106-
107-
// Upload the image to R2 and get the URL
108-
await r2Client.send(new PutObjectCommand(uploadParams));
109-
const r2Url = `https://${process.env.R2_ACCOUNT_ID}.r2.cloudflarestorage.com/${process.env.R2_BUCKET}/${r2Key}`;
110-
logger.log("Optimized image uploaded to R2", { url: r2Url });
111-
112-
// Delete the temporary file
113-
await fs.unlink(outputPath);
114-
115-
// Return the optimized image buffer, file path, and R2 URL
116-
return {
117-
optimizedImageBuffer,
118-
optimizedImagePath: outputPath,
119-
r2Url,
120-
};
90+
.jpeg() // Convert to jpeg
91+
.toBuffer() // Convert to buffer
92+
.then(async (outputBuffer) => {
93+
await fs.writeFile(outputPath, outputBuffer); // Write the buffer to file
94+
95+
const r2Key = `processed-images/${path.basename(outputPath)}`;
96+
const uploadParams = {
97+
Bucket: process.env.R2_BUCKET,
98+
Key: r2Key,
99+
Body: await fs.readFile(outputPath),
100+
};
101+
102+
const upload = new Upload({
103+
client: r2Client,
104+
params: uploadParams,
105+
});
106+
107+
await upload.done();
108+
logger.log("Image uploaded to R2 storage.", {
109+
path: `/${process.env.R2_BUCKET}/${r2Key}`,
110+
});
111+
112+
await fs.unlink(outputPath); // Clean up the temporary file
113+
return { r2Key };
114+
});
121115
},
122116
});
123117
```
@@ -133,4 +127,4 @@ To test this task in the dashboard, you can use the following payload:
133127
}
134128
```
135129

136-
<LocalDevelopment packages={"the Sharp image processing library"} />
130+
<LocalDevelopment packages={"the Sharp image processing library"} />

docs/tasks/scheduled.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: "Scheduled tasks (cron)"
33
description: "A task that is triggered on a recurring schedule using cron syntax."
44
---
55

6+
<Note>Scheduled tasks are only for recurring tasks. If you want to trigger a one-off task at a future time, you should [use the delay option](/triggering#delay).</Note>
7+
68
## Defining a scheduled task
79

810
This task will run when any of the attached schedules trigger. They have a predefined payload with some useful properties:

packages/core/src/v3/schemas/messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ export const CoordinatorToPlatformMessages = {
453453
CHECKPOINT_CREATED: {
454454
message: z.object({
455455
version: z.literal("v1").default("v1"),
456+
runId: z.string().optional(),
456457
attemptFriendlyId: z.string(),
457458
docker: z.boolean(),
458459
location: z.string(),

0 commit comments

Comments
 (0)