Skip to content

Commit eded802

Browse files
nicktrnmatt-aitken
authored andcommitted
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
1 parent e359aae commit eded802

File tree

3 files changed

+83
-5
lines changed

3 files changed

+83
-5
lines changed

apps/webapp/app/v3/models/workerDeployment.server.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export async function findCurrentWorkerDeployment(
7171
id: true,
7272
imageReference: true,
7373
version: true,
74+
type: true,
7475
worker: {
7576
select: {
7677
id: true,
@@ -88,7 +89,49 @@ export async function findCurrentWorkerDeployment(
8889
},
8990
});
9091

91-
return promotion?.deployment;
92+
if (!promotion) {
93+
return undefined;
94+
}
95+
96+
if (promotion.deployment.type === "V1") {
97+
// This is a run engine v1 deployment, so return it
98+
return promotion.deployment;
99+
}
100+
101+
// We need to get the latest run engine v1 deployment
102+
const latestV1Deployment = await prisma.workerDeployment.findFirst({
103+
where: {
104+
environmentId,
105+
type: "V1",
106+
},
107+
orderBy: {
108+
id: "desc",
109+
},
110+
select: {
111+
id: true,
112+
imageReference: true,
113+
version: true,
114+
type: true,
115+
worker: {
116+
select: {
117+
id: true,
118+
friendlyId: true,
119+
version: true,
120+
sdkVersion: true,
121+
cliVersion: true,
122+
supportsLazyAttempts: true,
123+
tasks: true,
124+
engine: true,
125+
},
126+
},
127+
},
128+
});
129+
130+
if (!latestV1Deployment) {
131+
return undefined;
132+
}
133+
134+
return latestV1Deployment;
92135
}
93136

94137
export async function getCurrentWorkerDeploymentEngineVersion(

internal-packages/run-engine/src/engine/db/worker.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,43 @@ export async function getWorkerFromCurrentlyPromotedDeployment(
289289
return null;
290290
}
291291

292+
if (promotion.deployment.type === "MANAGED") {
293+
// This is a run engine v2 deployment, so return it
294+
return {
295+
worker: promotion.deployment.worker,
296+
tasks: promotion.deployment.worker.tasks,
297+
queues: promotion.deployment.worker.queues,
298+
deployment: promotion.deployment,
299+
};
300+
}
301+
302+
// We need to get the latest run engine v2 deployment
303+
const latestV2Deployment = await prisma.workerDeployment.findFirst({
304+
where: {
305+
environmentId,
306+
type: "MANAGED",
307+
},
308+
orderBy: {
309+
id: "desc",
310+
},
311+
include: {
312+
worker: {
313+
include: {
314+
tasks: true,
315+
queues: true,
316+
},
317+
},
318+
},
319+
});
320+
321+
if (!latestV2Deployment?.worker) {
322+
return null;
323+
}
324+
292325
return {
293-
worker: promotion.deployment.worker,
294-
tasks: promotion.deployment.worker.tasks,
295-
queues: promotion.deployment.worker.queues,
296-
deployment: promotion.deployment,
326+
worker: latestV2Deployment.worker,
327+
tasks: latestV2Deployment.worker.tasks,
328+
queues: latestV2Deployment.worker.queues,
329+
deployment: latestV2Deployment,
297330
};
298331
}

internal-packages/run-engine/src/engine/tests/setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export async function setupBackgroundWorker(
9797
runtimeEnvironmentId: environment.id,
9898
version: nextVersion,
9999
metadata: {},
100+
engine: "V2",
100101
},
101102
});
102103

@@ -234,6 +235,7 @@ export async function setupBackgroundWorker(
234235
projectId: environment.project.id,
235236
environmentId: environment.id,
236237
workerId: worker.id,
238+
type: "MANAGED",
237239
},
238240
});
239241

0 commit comments

Comments
 (0)