Skip to content

Commit 5c967dc

Browse files
authored
Merge branch 'main' into main
2 parents ea208cb + a5a5d3a commit 5c967dc

File tree

6 files changed

+72
-1
lines changed

6 files changed

+72
-1
lines changed

.changeset/new-pants-beg.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 issue when using SDK in non-node environments by scoping the stream import with node:

apps/webapp/app/consts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export const VERCEL_RESPONSE_TIMEOUT_STATUS_CODES = [408, 504];
1313
export const MAX_BATCH_TRIGGER_ITEMS = 100;
1414
export const MAX_TASK_RUN_ATTEMPTS = 250;
1515
export const BULK_ACTION_RUN_LIMIT = 250;
16+
export const MAX_JOB_RUN_EXECUTION_COUNT = 250;

apps/webapp/app/services/runs/performRunExecutionV3.server.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import { generateErrorMessage } from "zod-error";
2626
import { eventRecordToApiJson } from "~/api.server";
2727
import {
28+
MAX_JOB_RUN_EXECUTION_COUNT,
2829
MAX_RUN_CHUNK_EXECUTION_LIMIT,
2930
MAX_RUN_YIELDED_EXECUTIONS,
3031
RUN_CHUNK_EXECUTION_BUFFER,
@@ -141,6 +142,46 @@ export class PerformRunExecutionV3Service {
141142
});
142143
}
143144

145+
if (run.version.status === "DISABLED") {
146+
return await this.#failRunExecution(
147+
this.#prismaClient,
148+
run,
149+
{
150+
message: `Job version ${run.version.version} is disabled, aborting run.`,
151+
},
152+
"ABORTED"
153+
);
154+
}
155+
156+
// If the execution duration is greater than the maximum execution time, we need to fail the run
157+
if (run.executionDuration >= run.organization.maximumExecutionTimePerRunInMs) {
158+
await this.#failRunExecution(
159+
this.#prismaClient,
160+
run,
161+
{
162+
message: `Execution timed out after ${
163+
run.organization.maximumExecutionTimePerRunInMs / 1000
164+
} seconds`,
165+
},
166+
"TIMED_OUT",
167+
0
168+
);
169+
return;
170+
}
171+
172+
if (run.executionCount >= MAX_JOB_RUN_EXECUTION_COUNT) {
173+
await this.#failRunExecution(
174+
this.#prismaClient,
175+
run,
176+
{
177+
message: `Execution timed out after ${run.executionCount} executions`,
178+
},
179+
"TIMED_OUT",
180+
0
181+
);
182+
return;
183+
}
184+
144185
const client = new EndpointApi(run.environment.apiKey, run.endpoint.url);
145186
const event = eventRecordToApiJson(run.event);
146187

packages/core/src/v3/zodfetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { APIConnectionError, APIError } from "./apiErrors";
44
import { RetryOptions } from "./schemas";
55
import { calculateNextRetryDelay } from "./utils/retries";
66
import { FormDataEncoder } from "form-data-encoder";
7-
import { Readable } from "stream";
7+
import { Readable } from "node:stream";
88

99
export const defaultRetryOptions = {
1010
maxAttempts: 3,

packages/core/tsup.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export default defineConfig({
1616
"./src/v3/prod/index.ts",
1717
"./src/v3/workers/index.ts",
1818
],
19+
external: ["node:stream"],
1920
});

references/job-catalog/src/stressTest.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@ client.defineJob({
3737
},
3838
});
3939

40+
client.defineJob({
41+
id: "stress-test-disabled",
42+
name: "Stress Test Disabled",
43+
version: "1.0.0",
44+
trigger: eventTrigger({
45+
name: "stress.test.disabled",
46+
}),
47+
enabled: false,
48+
run: async (payload, io, ctx) => {
49+
await io.wait("wait-1", 20);
50+
51+
await io.runTask(
52+
`task-1`,
53+
async (task) => {
54+
await new Promise((resolve) => setTimeout(resolve, 10000));
55+
},
56+
{ name: `Task 1` }
57+
);
58+
59+
await io.wait("wait-2", 5);
60+
},
61+
});
62+
4063
client.defineJob({
4164
id: "stress-test-2",
4265
name: "Stress Test 2",

0 commit comments

Comments
 (0)