Skip to content

Both run engines will only lock to versions they can handle #1922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
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
45 changes: 44 additions & 1 deletion apps/webapp/app/v3/models/workerDeployment.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export async function findCurrentWorkerDeployment(
id: true,
imageReference: true,
version: true,
type: true,
worker: {
select: {
id: true,
Expand All @@ -88,7 +89,49 @@ export async function findCurrentWorkerDeployment(
},
});

return promotion?.deployment;
if (!promotion) {
return undefined;
}

if (promotion.deployment.type === "V1") {
// This is a run engine v1 deployment, so return it
return promotion.deployment;
}

// We need to get the latest run engine v1 deployment
const latestV1Deployment = await prisma.workerDeployment.findFirst({
where: {
environmentId,
type: "V1",
},
orderBy: {
id: "desc",
},
select: {
id: true,
imageReference: true,
version: true,
type: true,
worker: {
select: {
id: true,
friendlyId: true,
version: true,
sdkVersion: true,
cliVersion: true,
supportsLazyAttempts: true,
tasks: true,
engine: true,
},
},
},
});

if (!latestV1Deployment) {
return undefined;
}

return latestV1Deployment;
}

export async function getCurrentWorkerDeploymentEngineVersion(
Expand Down
41 changes: 37 additions & 4 deletions internal-packages/run-engine/src/engine/db/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,43 @@ export async function getWorkerFromCurrentlyPromotedDeployment(
return null;
}

if (promotion.deployment.type === "MANAGED") {
// This is a run engine v2 deployment, so return it
return {
worker: promotion.deployment.worker,
tasks: promotion.deployment.worker.tasks,
queues: promotion.deployment.worker.queues,
deployment: promotion.deployment,
};
}

// We need to get the latest run engine v2 deployment
const latestV2Deployment = await prisma.workerDeployment.findFirst({
where: {
environmentId,
type: "MANAGED",
},
orderBy: {
id: "desc",
},
include: {
worker: {
include: {
tasks: true,
queues: true,
},
},
},
});

if (!latestV2Deployment?.worker) {
return null;
}

return {
worker: promotion.deployment.worker,
tasks: promotion.deployment.worker.tasks,
queues: promotion.deployment.worker.queues,
deployment: promotion.deployment,
worker: latestV2Deployment.worker,
tasks: latestV2Deployment.worker.tasks,
queues: latestV2Deployment.worker.queues,
deployment: latestV2Deployment,
};
}
2 changes: 2 additions & 0 deletions internal-packages/run-engine/src/engine/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export async function setupBackgroundWorker(
runtimeEnvironmentId: environment.id,
version: nextVersion,
metadata: {},
engine: "V2",
},
});

Expand Down Expand Up @@ -234,6 +235,7 @@ export async function setupBackgroundWorker(
projectId: environment.project.id,
environmentId: environment.id,
workerId: worker.id,
type: "MANAGED",
},
});

Expand Down