Skip to content

Commit 30ba73c

Browse files
committed
Various run execution fixes (incl massive memory bloat issue)
This commit fixes various issues with run executions, including a pretty gnarly memory bloat issue when resuming a run that had a decent number of completed tasks (e.g. anything over a few). Other issues fixed: - Run executions no longer are bound to a queue, which will allow more parallel runs in a single job (instead of 1). - Serverless function timeouts (504) errors are now handled better, and no longer are retried using the graphile worker failure/retry mechanism (causing massive delays). - Fixed the job_key design of the performRunExecutionV2 task, which will ensure resumed runs are executed - Added a mechanism to measure the amount of execution time a given run has accrued, and added a maximum execution duration on the org to be able to limit total execution time for a single run
1 parent bf6a2a0 commit 30ba73c

File tree

10 files changed

+258
-106
lines changed

10 files changed

+258
-106
lines changed

apps/webapp/app/components/run/RunCompletedDetail.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function RunCompletedDetail({ run }: { run: MatchedRun }) {
5454
<RunPanelDivider />
5555
{run.error && <RunPanelError text={run.error.message} stackTrace={run.error.stack} />}
5656
{run.output ? (
57-
<CodeBlock language="json" code={run.output} maxLines={8} />
57+
<CodeBlock language="json" code={run.output} maxLines={36} />
5858
) : (
5959
run.output === null && <Paragraph variant="small">This run returned nothing</Paragraph>
6060
)}

apps/webapp/app/models/jobRunExecution.server.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type EnqueueRunExecutionV2Options = {
2828
resumeTaskId?: string;
2929
isRetry?: boolean;
3030
skipRetrying?: boolean;
31+
executionCount?: number;
3132
};
3233

3334
export async function enqueueRunExecutionV2(
@@ -44,10 +45,11 @@ export async function enqueueRunExecutionV2(
4445
isRetry: typeof options.isRetry === "boolean" ? options.isRetry : false,
4546
},
4647
{
47-
queueName: `job:${run.jobId}:env:${run.environmentId}`,
4848
tx,
4949
runAt: options.runAt,
50-
jobKey: `job_run:${run.id}`,
50+
jobKey: `job_run:${run.id}:${options.executionCount ?? 0}${
51+
options.resumeTaskId ? `:task:${options.resumeTaskId}` : ""
52+
}`,
5153
maxAttempts: options.skipRetrying ? 1 : undefined,
5254
}
5355
);

apps/webapp/app/services/endpointApi.server.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from "@trigger.dev/core";
1919
import { safeBodyFromResponse, safeParseBodyFromResponse } from "~/utils/json";
2020
import { logger } from "./logger.server";
21+
import { performance } from "node:perf_hooks";
2122

2223
export class EndpointApiError extends Error {
2324
constructor(message: string, stack?: string) {
@@ -28,10 +29,7 @@ export class EndpointApiError extends Error {
2829
}
2930

3031
export class EndpointApi {
31-
constructor(
32-
private apiKey: string,
33-
private url: string
34-
) {}
32+
constructor(private apiKey: string, private url: string) {}
3533

3634
async ping(endpointId: string): Promise<PongResponse> {
3735
const response = await safeFetch(this.url, {
@@ -165,9 +163,7 @@ export class EndpointApi {
165163
}
166164

167165
async executeJobRequest(options: RunJobBody) {
168-
logger.debug("executeJobRequest()", {
169-
options,
170-
});
166+
const startTimeInMs = performance.now();
171167

172168
const response = await safeFetch(this.url, {
173169
method: "POST",
@@ -183,6 +179,7 @@ export class EndpointApi {
183179
response,
184180
parser: RunJobResponseSchema,
185181
errorParser: ErrorWithStackSchema,
182+
durationInMs: Math.floor(performance.now() - startTimeInMs),
186183
};
187184
}
188185

0 commit comments

Comments
 (0)