Skip to content

Commit 6914bc3

Browse files
planetscale[bot]Trigger.dev RepoOps
authored andcommitted
Return only needed columns from the dequeue TaskRun lock update
Mono-RevId: a2183b7e2b892a6766df703cfc4f0603640abc05
1 parent 1d64d6d commit 6914bc3

5 files changed

Lines changed: 44 additions & 7 deletions

File tree

‎internal-packages/run-store/src/PostgresRunStore.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import type {
3131
ForWaitpointCompletionContext,
3232
IdempotencyKeyRunMatch,
3333
LatestExecutionSnapshotRead,
34+
LockedRun,
3435
LockRunData,
3536
PromotePendingVersionArgs,
3637
ReadClient,
@@ -40,6 +41,7 @@ import type {
4041
StateHeldCheckpointInput,
4142
TaskRunWithWaitpoint,
4243
} from "./types.js";
44+
import { lockedRunSelect } from "./types.js";
4345
import { isReadReplicaClient } from "./readReplicaClient.js";
4446
import type { TaskRunError } from "@trigger.dev/core/v3/schemas";
4547
import type { ShardKey } from "@trigger.dev/core/v3/isomorphic";
@@ -1177,7 +1179,7 @@ export class PostgresRunStore implements RunStore {
11771179
runId: string,
11781180
data: LockRunData,
11791181
tx?: PrismaClientOrTransaction
1180-
): Promise<Prisma.TaskRunGetPayload<{}>> {
1182+
): Promise<LockedRun> {
11811183
// The run-lock update (with its nested PENDING_EXECUTING snapshot) and the completed-waitpoint
11821184
// connect must commit together, or a replica-served resume read can see the snapshot without its
11831185
// links and drop the resume.
@@ -1188,7 +1190,7 @@ export class PostgresRunStore implements RunStore {
11881190
runId: string,
11891191
data: LockRunData,
11901192
prisma: PrismaClientOrTransaction
1191-
): Promise<Prisma.TaskRunGetPayload<{}>> {
1193+
): Promise<LockedRun> {
11921194
const dedicated = this.schemaVariant === "dedicated";
11931195

11941196
// Resolve the snapshot-write decision ONCE for both the nested snapshot below and the join-row
@@ -1240,6 +1242,7 @@ export class PostgresRunStore implements RunStore {
12401242
writesSnapshot
12411243
),
12421244
},
1245+
select: lockedRunSelect,
12431246
});
12441247

12451248
// The join rows link to the snapshot row above. With snapshot writes off there is no such row,

‎internal-packages/run-store/src/delegatingRunStore.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import type {
3939
ForWaitpointCompletionContext,
4040
IdempotencyKeyRunMatch,
4141
LatestExecutionSnapshotRead,
42+
LockedRun,
4243
LockRunData,
4344
PromotePendingVersionArgs,
4445
ReadClient,
@@ -210,7 +211,7 @@ export class DelegatingRunStore implements RunStore {
210211
runId: string,
211212
data: LockRunData,
212213
tx?: PrismaClientOrTransaction
213-
): Promise<Prisma.TaskRunGetPayload<{}>> {
214+
): Promise<LockedRun> {
214215
return this.delegate.lockRunToWorker(runId, data, tx);
215216
}
216217

‎internal-packages/run-store/src/runOpsStore.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import type {
2525
ForWaitpointCompletionContext,
2626
IdempotencyKeyRunMatch,
2727
LatestExecutionSnapshotRead,
28+
LockedRun,
2829
LockRunData,
2930
PromotePendingVersionArgs,
3031
ReadClient,
@@ -1161,7 +1162,7 @@ export class RoutingRunStore implements RunStore {
11611162
runId: string,
11621163
data: LockRunData,
11631164
tx?: PrismaClientOrTransaction
1164-
): Promise<Prisma.TaskRunGetPayload<{}>> {
1165+
): Promise<LockedRun> {
11651166
return (await this.#routeForWrite(runId)).lockRunToWorker(runId, data);
11661167
}
11671168

‎internal-packages/run-store/src/taskRunExecutionSnapshotStore.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import type {
2929
CreateRunInput,
3030
ExpireSnapshotInput,
3131
LatestExecutionSnapshotRead,
32+
LockedRun,
3233
LockRunData,
3334
ReadClient,
3435
SnapshotReadWaitpoint,
@@ -429,7 +430,7 @@ class CapturingTxStore extends DelegatingRunStore {
429430
runId: string,
430431
data: LockRunData,
431432
tx?: PrismaClientOrTransaction
432-
): Promise<Prisma.TaskRunGetPayload<{}>> {
433+
): Promise<LockedRun> {
433434
const organizationId = this.deps.organizationId ?? data.snapshot.organizationId;
434435
this.#assertBoundRun(runId);
435436
const residency = await this.#residencyFor(
@@ -809,7 +810,7 @@ export class TaskRunExecutionSnapshotStore extends DelegatingRunStore {
809810
runId: string,
810811
data: LockRunData,
811812
tx?: PrismaClientOrTransaction
812-
): Promise<Prisma.TaskRunGetPayload<{}>> {
813+
): Promise<LockedRun> {
813814
const organizationId = this.#organizationId ?? data.snapshot.organizationId;
814815
const residency = await this.#writeResidency(
815816
runId,

‎internal-packages/run-store/src/types.ts‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,37 @@ export type LockRunData = {
319319
snapshot: LockSnapshotInput;
320320
};
321321

322+
/**
323+
* Columns `lockRunToWorker` returns. Dequeue runs this update for every run, so it returns only
324+
* what the dequeue result and `runLocked` event read, not payload, output or metadata.
325+
*/
326+
export const lockedRunSelect = {
327+
id: true,
328+
friendlyId: true,
329+
status: true,
330+
attemptNumber: true,
331+
isTest: true,
332+
replayedFromTaskRunFriendlyId: true,
333+
workerQueue: true,
334+
traceContext: true,
335+
annotations: true,
336+
planType: true,
337+
runTags: true,
338+
batchId: true,
339+
projectId: true,
340+
runtimeEnvironmentId: true,
341+
maxAttempts: true,
342+
maxDurationInSeconds: true,
343+
lockedAt: true,
344+
lockedById: true,
345+
lockedToVersionId: true,
346+
lockedQueueId: true,
347+
createdAt: true,
348+
updatedAt: true,
349+
} satisfies Prisma.TaskRunSelect;
350+
351+
export type LockedRun = Prisma.TaskRunGetPayload<{ select: typeof lockedRunSelect }>;
352+
322353
export type RewriteDebouncedRunData = {
323354
payload: string;
324355
payloadType: string;
@@ -630,7 +661,7 @@ export interface RunStore {
630661
runId: string,
631662
data: LockRunData,
632663
tx?: PrismaClientOrTransaction
633-
): Promise<Prisma.TaskRunGetPayload<{}>>;
664+
): Promise<LockedRun>;
634665
parkPendingVersion<S extends Prisma.TaskRunSelect>(
635666
runId: string,
636667
data: { statusReason: string },

0 commit comments

Comments
 (0)