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

* run engine v1 will only lock to v1 deployments

* run engine v2 will only lock to managed v2 deployments

* test: create background worker and deployment with correct engine version
This commit is contained in:
nicktrn
2025-04-13 21:51:42 +01:00
committed by GitHub
parent 1d920d5b3f
commit faf5d01b2c
3 changed files with 83 additions and 5 deletions
@@ -71,6 +71,7 @@ export async function findCurrentWorkerDeployment(
id: true,
imageReference: true,
version: true,
type: true,
worker: {
select: {
id: true,
@@ -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(
@@ -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,
};
}
@@ -97,6 +97,7 @@ export async function setupBackgroundWorker(
runtimeEnvironmentId: environment.id,
version: nextVersion,
metadata: {},
engine: "V2",
},
});
@@ -234,6 +235,7 @@ export async function setupBackgroundWorker(
projectId: environment.project.id,
environmentId: environment.id,
workerId: worker.id,
type: "MANAGED",
},
});