v4 engine version selection logic updated (#1866)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { RunEngineVersion, type RuntimeEnvironmentType } from "@trigger.dev/database";
|
||||
import {
|
||||
findCurrentWorkerDeploymentWithoutTasks,
|
||||
findCurrentWorkerFromEnvironment,
|
||||
} from "./models/workerDeployment.server";
|
||||
import { $replica } from "~/db.server";
|
||||
import {
|
||||
findCurrentWorkerFromEnvironment,
|
||||
getCurrentWorkerDeploymentEngineVersion,
|
||||
} from "./models/workerDeployment.server";
|
||||
|
||||
type Environment = {
|
||||
id: string;
|
||||
@@ -65,10 +65,12 @@ export async function determineEngineVersion({
|
||||
}
|
||||
|
||||
// Deployed: use the latest deployed BackgroundWorker
|
||||
const currentDeployment = await findCurrentWorkerDeploymentWithoutTasks(environment.id);
|
||||
if (currentDeployment?.type === "V1") {
|
||||
return "V1";
|
||||
const currentDeploymentEngineVersion = await getCurrentWorkerDeploymentEngineVersion(
|
||||
environment.id
|
||||
);
|
||||
if (currentDeploymentEngineVersion) {
|
||||
return currentDeploymentEngineVersion;
|
||||
}
|
||||
|
||||
return "V2";
|
||||
return environment.project.engine;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Prettify } from "@trigger.dev/core";
|
||||
import { BackgroundWorker, WorkerDeployment } from "@trigger.dev/database";
|
||||
import { BackgroundWorker, RunEngineVersion, WorkerDeployment } from "@trigger.dev/database";
|
||||
import {
|
||||
CURRENT_DEPLOYMENT_LABEL,
|
||||
CURRENT_UNMANAGED_DEPLOYMENT_LABEL,
|
||||
@@ -91,23 +91,29 @@ export async function findCurrentWorkerDeployment(
|
||||
return promotion?.deployment;
|
||||
}
|
||||
|
||||
export async function findCurrentWorkerDeploymentWithoutTasks(
|
||||
export async function getCurrentWorkerDeploymentEngineVersion(
|
||||
environmentId: string,
|
||||
label = CURRENT_DEPLOYMENT_LABEL
|
||||
): Promise<WorkerDeployment | undefined> {
|
||||
const promotion = await prisma.workerDeploymentPromotion.findUnique({
|
||||
): Promise<RunEngineVersion | undefined> {
|
||||
const promotion = await prisma.workerDeploymentPromotion.findFirst({
|
||||
where: {
|
||||
environmentId_label: {
|
||||
environmentId,
|
||||
label,
|
||||
},
|
||||
environmentId,
|
||||
label,
|
||||
},
|
||||
include: {
|
||||
deployment: true,
|
||||
select: {
|
||||
deployment: {
|
||||
select: {
|
||||
type: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return promotion?.deployment;
|
||||
if (typeof promotion?.deployment.type === "string") {
|
||||
return promotion.deployment.type === "V1" ? "V1" : "V2";
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export async function findCurrentUnmanagedWorkerDeployment(
|
||||
|
||||
@@ -973,7 +973,7 @@ export class ApiClient {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${this.accessToken}`,
|
||||
"trigger-version": VERSION,
|
||||
"x-trigger-engine-version": taskContext.worker?.engine ?? "V2",
|
||||
"x-trigger-engine-version": "V2",
|
||||
...Object.entries(additionalHeaders ?? {}).reduce(
|
||||
(acc, [key, value]) => {
|
||||
if (value !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user