refactor(run-engine): move the run block-state read behind the coordinator
This commit is contained in:
@@ -683,20 +683,7 @@ export class WaitpointSystem {
|
||||
|
||||
return await this.$.runLock.lock("continueRunIfUnblocked", [runId], async () => {
|
||||
// 1. Get the any blocking waitpoints
|
||||
const blockingWaitpoints = await this.$.runStore.findManyTaskRunWaitpoints(
|
||||
{
|
||||
where: { taskRunId: runId },
|
||||
select: {
|
||||
id: true,
|
||||
batchId: true,
|
||||
batchIndex: true,
|
||||
waitpoint: {
|
||||
select: { id: true, status: true, type: true, completedAfter: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
this.$.prisma
|
||||
);
|
||||
const blockingWaitpoints = await this.coordinator.readRunBlockState(runId);
|
||||
|
||||
// 2. There are blockers still, so do nothing
|
||||
if (blockingWaitpoints.some((w) => w.waitpoint.status !== "COMPLETED")) {
|
||||
|
||||
+18
-1
@@ -2,7 +2,7 @@ import type { RunStore } from "@internal/run-store";
|
||||
import type { Logger } from "@trigger.dev/core/logger";
|
||||
import type { PrismaClient } from "@trigger.dev/database";
|
||||
import { boundedIn } from "@trigger.dev/database";
|
||||
import type { ClearRunBlockStateParams, WaitpointCoordinator } from "./types.js";
|
||||
import type { ClearRunBlockStateParams, RunBlockEdge, WaitpointCoordinator } from "./types.js";
|
||||
|
||||
export type LegacyPostgresWaitpointCoordinatorOptions = {
|
||||
runStore: RunStore;
|
||||
@@ -48,4 +48,21 @@ export class LegacyPostgresWaitpointCoordinator implements WaitpointCoordinator
|
||||
// passed through: a routing store strips it, and a single store joins it.
|
||||
return this.runStore.deleteManyTaskRunWaitpoints({ where: { taskRunId: runId } }, tx);
|
||||
}
|
||||
|
||||
async readRunBlockState(runId: string): Promise<RunBlockEdge[]> {
|
||||
return this.runStore.findManyTaskRunWaitpoints(
|
||||
{
|
||||
where: { taskRunId: runId },
|
||||
select: {
|
||||
id: true,
|
||||
batchId: true,
|
||||
batchIndex: true,
|
||||
waitpoint: {
|
||||
select: { id: true, status: true, type: true, completedAfter: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
this.prisma
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { PrismaClientOrTransaction } from "@trigger.dev/database";
|
||||
import type { PrismaClientOrTransaction, Waitpoint } from "@trigger.dev/database";
|
||||
|
||||
/**
|
||||
* The waitpoint and edge state operations that `WaitpointSystem` delegates.
|
||||
@@ -14,6 +14,7 @@ import type { PrismaClientOrTransaction } from "@trigger.dev/database";
|
||||
*/
|
||||
export type WaitpointCoordinator = {
|
||||
clearRunBlockState(params: ClearRunBlockStateParams): Promise<{ count: number }>;
|
||||
readRunBlockState(runId: string): Promise<RunBlockEdge[]>;
|
||||
};
|
||||
|
||||
export type ClearRunBlockStateParams = {
|
||||
@@ -26,3 +27,16 @@ export type ClearRunBlockStateParams = {
|
||||
*/
|
||||
tx?: PrismaClientOrTransaction;
|
||||
};
|
||||
|
||||
/**
|
||||
* One block edge, with the fields the unblock decision reads.
|
||||
*
|
||||
* `batchId` is read by no logic. It rides inside two `logger.debug` payloads
|
||||
* (`waitpointSystem.ts:702-705` and `:936-939`), so removing it changes log output.
|
||||
*/
|
||||
export type RunBlockEdge = {
|
||||
id: string;
|
||||
batchId: string | null;
|
||||
batchIndex: number | null;
|
||||
waitpoint: Pick<Waitpoint, "id" | "status" | "type" | "completedAfter">;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user