Skip to content

Commit d3a3951

Browse files
committed
add basic engine version check via current deploy
1 parent da41728 commit d3a3951

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

apps/webapp/app/v3/engineVersion.server.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { RunEngineVersion, RuntimeEnvironmentType } from "@trigger.dev/database";
22
import { AuthenticatedEnvironment } from "~/services/apiAuth.server";
3+
import { findCurrentWorkerDeploymentWithoutTasks } from "./models/workerDeployment.server";
34

45
export async function determineEngineVersion({
56
environment,
@@ -8,7 +9,9 @@ export async function determineEngineVersion({
89
environment: AuthenticatedEnvironment;
910
version?: RunEngineVersion;
1011
}): Promise<RunEngineVersion> {
11-
if (version) return version;
12+
if (version) {
13+
return version;
14+
}
1215

1316
// If the project is V1, then none of the background workers are running V2
1417
if (environment.project.engine === RunEngineVersion.V1) {
@@ -20,6 +23,16 @@ export async function determineEngineVersion({
2023
return "V1";
2124
}
2225

26+
/**
27+
* The project has V2 enabled and this isn't dev
28+
*/
29+
30+
// Check the current deployment for this environment
31+
const currentDeployment = await findCurrentWorkerDeploymentWithoutTasks(environment.id);
32+
if (currentDeployment?.type === "V1") {
33+
return "V1";
34+
}
35+
2336
//todo we need to determine the version using the BackgroundWorker
2437
//- triggerAndWait we can lookup the BackgroundWorker easily, and get the engine.
2538
//- No locked version: lookup the BackgroundWorker via the Deployment/latest dev BW

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Prettify } from "@trigger.dev/core";
2-
import { BackgroundWorker } from "@trigger.dev/database";
2+
import { BackgroundWorker, WorkerDeployment } from "@trigger.dev/database";
33
import { CURRENT_DEPLOYMENT_LABEL, CURRENT_UNMANAGED_DEPLOYMENT_LABEL } from "~/consts";
44
import { Prisma, prisma } from "~/db.server";
55
import { AuthenticatedEnvironment } from "~/services/apiAuth.server";
@@ -45,6 +45,25 @@ export async function findCurrentWorkerDeployment(
4545
return promotion?.deployment;
4646
}
4747

48+
export async function findCurrentWorkerDeploymentWithoutTasks(
49+
environmentId: string,
50+
label = CURRENT_DEPLOYMENT_LABEL
51+
): Promise<WorkerDeployment | undefined> {
52+
const promotion = await prisma.workerDeploymentPromotion.findUnique({
53+
where: {
54+
environmentId_label: {
55+
environmentId,
56+
label,
57+
},
58+
},
59+
include: {
60+
deployment: true,
61+
},
62+
});
63+
64+
return promotion?.deployment;
65+
}
66+
4867
export async function findCurrentUnmanagedWorkerDeployment(
4968
environmentId: string
5069
): Promise<WorkerDeploymentWithWorkerTasks | undefined> {

0 commit comments

Comments
 (0)