Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions internal-packages/run-engine/src/engine/systems/waitpointSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export class WaitpointSystem {
};
}): Promise<Waitpoint> {
// 1. Complete the Waitpoint (if not completed)
let [waitpointError, waitpoint] = await tryCatch(
this.$.prisma.waitpoint.update({
const [updateError, updateResult] = await tryCatch(
this.$.prisma.waitpoint.updateMany({
where: { id, status: "PENDING" },
data: {
status: "COMPLETED",
Expand All @@ -92,29 +92,32 @@ export class WaitpointSystem {
})
);

if (waitpointError) {
if (
waitpointError instanceof Prisma.PrismaClientKnownRequestError &&
waitpointError.code === "P2025"
) {
waitpoint = await this.$.prisma.waitpoint.findFirst({
where: { id },
});
} else {
this.$.logger.log("completeWaitpoint: error updating waitpoint:", { waitpointError });
throw waitpointError;
}
if (updateError) {
this.$.logger.error("completeWaitpoint: error updating waitpoint:", { updateError });
throw updateError;
}

if (updateResult.count === 0) {
this.$.logger.info(
"completeWaitpoint: attempted to complete a waitpoint that is not PENDING",
{ waitpointId: id }
);
}

const waitpoint = await this.$.prisma.waitpoint.findFirst({
where: { id },
});

if (!waitpoint) {
throw new Error(`Waitpoint ${id} not found`);
this.$.logger.error("completeWaitpoint: waitpoint not found", { waitpointId: id });
throw new Error("Waitpoint not found");
}

if (waitpoint.status !== "COMPLETED") {
this.$.logger.error(`completeWaitpoint: waitpoint is not completed`, {
waitpointId: id,
});
throw new Error(`Waitpoint ${id} is not completed`);
throw new Error("Waitpoint not completed");
}

// 2. Find the TaskRuns blocked by this waitpoint
Expand Down
Loading