Skip to content

Commit 313423f

Browse files
committed
Merge remote-tracking branch 'origin/main' into docs/task-examples
2 parents ddce0f2 + 47ca24a commit 313423f

File tree

108 files changed

+19258
-592
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+19258
-592
lines changed

.changeset/curvy-beers-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Fixed empty env vars overriding in dev runs

.changeset/gentle-planets-return.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/build": patch
3+
---
4+
5+
Fix issue with emitDecoratorMetadata and tsconfigs with extends

.changeset/mighty-sheep-guess.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@trigger.dev/sdk": patch
3+
"trigger.dev": patch
4+
"@trigger.dev/core": patch
5+
---
6+
7+
Support self-hosters pushing to a custom registry when running deploy

.changeset/proud-dogs-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/build": patch
3+
---
4+
5+
Add support for prisma typed sql

.changeset/rude-houses-promise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Fix --project-ref when running deploy

.changeset/strong-years-help.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Fixed stuck runs when a child run fails with a process exit

.changeset/tidy-roses-guess.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"trigger.dev": patch
3+
"@trigger.dev/core": patch
4+
---
5+
6+
Add remote forced externals system, in case we come across another package that cannot be bundled (spurred on by header-generator)

.changeset/twenty-seahorses-admire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/sdk": patch
3+
---
4+
5+
Remove msw and retry.interceptFetch

.changeset/violet-cherries-deny.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/core": patch
3+
---
4+
5+
fix node10 moduleResolution in @trigger.dev/core

.changeset/wise-pens-agree.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"trigger.dev": patch
3+
"@trigger.dev/core": patch
4+
---
5+
6+
Only import import-in-the-middle hook if there are instrumented packages

.vscode/launch.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@
2020
"url": "http://localhost:3030",
2121
"webRoot": "${workspaceFolder}/apps/webapp/app"
2222
},
23-
{
24-
"type": "node-terminal",
25-
"request": "launch",
26-
"name": "Debug v2 job catalog",
27-
"command": "pnpm run byo-auth",
28-
"envFile": "${workspaceFolder}/references/job-catalog/.env",
29-
"cwd": "${workspaceFolder}/references/job-catalog",
30-
"sourceMaps": true
31-
},
3223
{
3324
"type": "node-terminal",
3425
"request": "launch",
@@ -89,9 +80,17 @@
8980
"type": "node-terminal",
9081
"request": "launch",
9182
"name": "Debug CLI e2e tests",
92-
"command": "PM=yarn pnpm run test:e2e",
83+
"command": "MOD=otel-telemetry-loader pnpm run test:e2e",
9384
"cwd": "${workspaceFolder}/packages/cli-v3",
9485
"sourceMaps": true
86+
},
87+
{
88+
"type": "node-terminal",
89+
"request": "launch",
90+
"name": "debug v3 hello-world dev",
91+
"command": "pnpm exec triggerdev dev",
92+
"cwd": "${workspaceFolder}/references/hello-world",
93+
"sourceMaps": true
9594
}
9695
]
9796
}

apps/webapp/app/presenters/v3/UsagePresenter.server.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,18 @@ export class UsagePresenter extends BasePresenter {
105105
//usage by task
106106
const tasks = this._replica.$queryRaw<TaskUsageItem[]>`
107107
SELECT
108-
tr."taskIdentifier",
109-
COUNT(*) AS "runCount",
110-
AVG(tr."usageDurationMs") AS "averageDuration",
111-
SUM(tr."usageDurationMs") AS "totalDuration",
112-
AVG(tr."costInCents") / 100.0 AS "averageCost",
113-
SUM(tr."costInCents") / 100.0 AS "totalCost",
114-
SUM(tr."baseCostInCents") / 100.0 AS "totalBaseCost"
108+
tr."taskIdentifier",
109+
COUNT(*) AS "runCount",
110+
AVG(tr."usageDurationMs") AS "averageDuration",
111+
SUM(tr."usageDurationMs") AS "totalDuration",
112+
AVG(tr."costInCents") / 100.0 AS "averageCost",
113+
SUM(tr."costInCents") / 100.0 AS "totalCost",
114+
SUM(tr."baseCostInCents") / 100.0 AS "totalBaseCost"
115115
FROM
116116
${sqlDatabaseSchema}."TaskRun" tr
117117
JOIN ${sqlDatabaseSchema}."Project" pr ON pr.id = tr."projectId"
118118
JOIN ${sqlDatabaseSchema}."Organization" org ON org.id = pr."organizationId"
119-
JOIN ${sqlDatabaseSchema}."RuntimeEnvironment" env ON env."projectId" = pr.id
119+
JOIN ${sqlDatabaseSchema}."RuntimeEnvironment" env ON env."id" = tr."runtimeEnvironmentId"
120120
WHERE
121121
env.type <> 'DEVELOPMENT'
122122
AND tr."createdAt" > ${startOfMonth}
@@ -132,7 +132,7 @@ export class UsagePresenter extends BasePresenter {
132132
averageDuration: Number(item.averageDuration),
133133
averageCost: Number(item.averageCost) + env.CENTS_PER_RUN / 100,
134134
totalDuration: Number(item.totalDuration),
135-
totalCost: Number(item.totalCost + item.totalBaseCost),
135+
totalCost: Number(item.totalCost) + Number(item.totalBaseCost),
136136
}))
137137
.sort((a, b) => b.totalCost - a.totalCost);
138138
});

apps/webapp/app/routes/api.v1.deployments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
4343
externalBuildData:
4444
deployment.externalBuildData as InitializeDeploymentResponseBody["externalBuildData"],
4545
imageTag,
46-
registryHost: env.DEPLOY_REGISTRY_HOST,
46+
registryHost: body.data.registryHost ?? env.DEPLOY_REGISTRY_HOST,
4747
};
4848

4949
return json(responseBody, { status: 200 });

apps/webapp/app/routes/api.v1.usage.ingest.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ export async function action({ request }: ActionFunctionArgs) {
99
}
1010

1111
try {
12-
return await reportComputeUsage(request);
12+
const result = await reportComputeUsage(request);
13+
14+
if (result === undefined) {
15+
return new Response(null, { status: 500 });
16+
}
17+
18+
return result;
1319
} catch (e) {
1420
logger.error("Error reporting compute usage", { error: e });
1521
return new Response(null, { status: 500 });

apps/webapp/app/v3/otlpExporter.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ function isStringValue(value: AnyValue | undefined): value is { stringValue: str
693693
function isIntValue(value: AnyValue | undefined): value is { intValue: bigint } {
694694
if (!value) return false;
695695

696-
return typeof value.intValue === "number";
696+
return typeof value.intValue === "number" || typeof value.intValue === "bigint";
697697
}
698698

699699
function isDoubleValue(value: AnyValue | undefined): value is { doubleValue: number } {

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,43 @@ export class CreateCheckpointService extends BaseService {
169169
attemptId: attempt.id,
170170
taskRunId: attempt.taskRunId,
171171
type: "WAIT_FOR_TASK",
172+
reason,
172173
});
173174
await marqs?.cancelHeartbeat(attempt.taskRunId);
174175

176+
const childRun = await this._prisma.taskRun.findFirst({
177+
where: {
178+
friendlyId: reason.friendlyId,
179+
},
180+
});
181+
182+
if (!childRun) {
183+
logger.error("CreateCheckpointService: WAIT_FOR_TASK child run not found", {
184+
friendlyId: reason.friendlyId,
185+
});
186+
187+
return {
188+
success: true,
189+
checkpoint,
190+
event: checkpointEvent,
191+
keepRunAlive: false,
192+
};
193+
}
194+
175195
const resumeService = new ResumeDependentParentsService(this._prisma);
176-
const result = await resumeService.call({ id: attempt.taskRunId });
196+
const result = await resumeService.call({ id: childRun.id });
177197

178198
if (result.success) {
179199
logger.log("CreateCheckpointService: Resumed dependent parents", {
180200
result,
201+
childRun,
181202
attempt,
182203
checkpointEvent,
183204
});
184205
} else {
185206
logger.error("CreateCheckpointService: Failed to resume dependent parents", {
186207
result,
208+
childRun,
187209
attempt,
188210
checkpointEvent,
189211
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
syncDeclarativeSchedules,
1010
} from "./createBackgroundWorker.server";
1111
import { TimeoutDeploymentService } from "./timeoutDeployment.server";
12+
import { logger } from "~/services/logger.server";
1213

1314
export class CreateDeploymentBackgroundWorkerService extends BaseService {
1415
public async call(

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ export class InitializeDeploymentService extends BaseService {
2929
const nextVersion = calculateNextBuildVersion(latestDeployment?.version);
3030

3131
// Try and create a depot build and get back the external build data
32-
const externalBuildData = await createRemoteImageBuild(environment.project);
32+
const externalBuildData = !!payload.selfHosted
33+
? await createRemoteImageBuild(environment.project)
34+
: undefined;
3335

3436
const triggeredBy = payload.userId
3537
? await this._prisma.user.findUnique({
@@ -65,7 +67,9 @@ export class InitializeDeploymentService extends BaseService {
6567
new Date(Date.now() + 180_000) // 3 minutes
6668
);
6769

68-
const imageTag = `${env.DEPLOY_REGISTRY_NAMESPACE}/${environment.project.externalRef}:${deployment.version}.${environment.slug}`;
70+
const imageTag = `${payload.namespace ?? env.DEPLOY_REGISTRY_NAMESPACE}/${
71+
environment.project.externalRef
72+
}:${deployment.version}.${environment.slug}`;
6973

7074
return { deployment, imageTag };
7175
});

docker/docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,16 @@ services:
5757
- app_network
5858
ports:
5959
- 6379:6379
60+
61+
# otel-collector:
62+
# container_name: otel-collector
63+
# image: otel/opentelemetry-collector-contrib:latest
64+
# restart: always
65+
# command: ["--config", "/etc/otel-collector-config.yaml"]
66+
# volumes:
67+
# - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
68+
# ports:
69+
# - "55680:55680"
70+
# - "55681:55681"
71+
# - "4317:4317" # OTLP gRPC receiver
72+
# - "4318:4318" # OTLP http receiver

docker/otel-collector-config.yaml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,11 @@ receivers:
55
endpoint: 0.0.0.0:4317
66
http:
77
endpoint: 0.0.0.0:4318
8-
otlp/internal:
9-
protocols:
10-
http:
11-
endpoint: 0.0.0.0:4319
128

139
processors:
1410
batch:
1511

1612
exporters:
17-
otlphttp/internal:
18-
endpoint: "https://otel.baselime.io/v1/"
19-
headers:
20-
"x-api-key": ${env:BASELIME_API_KEY}
21-
"x-service": ${env:BASELIME_SERVICE}
22-
"x-baselime-dataset": "otel"
2313
logging:
2414
verbosity: normal
2515
otlphttp:
@@ -36,7 +26,3 @@ service:
3626
receivers: [otlp]
3727
processors: [batch]
3828
exporters: [otlphttp]
39-
traces/internal:
40-
receivers: [otlp/internal]
41-
processors: [batch]
42-
exporters: [otlphttp/internal]

docs/errors-retrying.mdx

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,11 @@ In this complicated example:
200200
- If there are no Response headers we let the normal retrying logic handle it (return undefined).
201201
- If we've run out of requests or tokens we retry at the time specified in the headers.
202202

203-
```ts
203+
<CodeGroup>
204+
205+
```ts tasks.ts
204206
import { task } from "@trigger.dev/sdk/v3";
207+
import { calculateISO8601DurationOpenAIVariantResetAt, openai } from "./openai.js";
205208

206209
export const openaiTask = task({
207210
id: "openai-task",
@@ -257,6 +260,48 @@ export const openaiTask = task({
257260
});
258261
```
259262

263+
```ts openai.ts
264+
import { OpenAI } from "openai";
265+
266+
export const openai = new OpenAI({ apiKey: env.OPENAI_API_KEY });
267+
268+
export function calculateISO8601DurationOpenAIVariantResetAt(
269+
resets: string,
270+
now: Date = new Date()
271+
): Date | undefined {
272+
// Check if the input is null or undefined
273+
if (!resets) return undefined;
274+
275+
// Regular expression to match the duration string pattern
276+
const pattern = /^(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+)ms)?$/;
277+
const match = resets.match(pattern);
278+
279+
// If the string doesn't match the expected format, return undefined
280+
if (!match) return undefined;
281+
282+
// Extract days, hours, minutes, seconds, and milliseconds from the string
283+
const days = parseInt(match[1] ?? "0", 10) || 0;
284+
const hours = parseInt(match[2] ?? "0", 10) || 0;
285+
const minutes = parseInt(match[3] ?? "0", 10) || 0;
286+
const seconds = parseFloat(match[4] ?? "0") || 0;
287+
const milliseconds = parseInt(match[5] ?? "0", 10) || 0;
288+
289+
// Calculate the future date based on the current date plus the extracted time
290+
const resetAt = new Date(now);
291+
resetAt.setDate(resetAt.getDate() + days);
292+
resetAt.setHours(resetAt.getHours() + hours);
293+
resetAt.setMinutes(resetAt.getMinutes() + minutes);
294+
resetAt.setSeconds(resetAt.getSeconds() + Math.floor(seconds));
295+
resetAt.setMilliseconds(
296+
resetAt.getMilliseconds() + (seconds - Math.floor(seconds)) * 1000 + milliseconds
297+
);
298+
299+
return resetAt;
300+
}
301+
```
302+
303+
</CodeGroup>
304+
260305
## Preventing retries
261306

262307
### Using `AbortTaskRunError`

0 commit comments

Comments
 (0)