@@ -4,6 +4,7 @@ import { WithRunEngine } from "./baseService.server";
44import { RunEngineVersion , RuntimeEnvironmentType } from "@trigger.dev/database" ;
55import { TriggerTaskServiceV1 } from "./triggerTaskV1.server" ;
66import { TriggerTaskServiceV2 } from "./triggerTaskV2.server" ;
7+ import { determineEngineVersion } from "../engineVersion.server" ;
78
89export type TriggerTaskServiceOptions = {
910 idempotencyKey ?: string ;
@@ -35,44 +36,16 @@ export class TriggerTaskService extends WithRunEngine {
3536 return await this . traceWithEnv ( "call()" , environment , async ( span ) => {
3637 span . setAttribute ( "taskId" , taskId ) ;
3738
38- //todo we need to determine the version using the BackgroundWorker
39- //- triggerAndWait we can lookup the BackgroundWorker easily, and get the engine.
40- //- No locked version: lookup the BackgroundWorker via the Deployment/latest dev BW
41- // const workerWithTasks = workerId
42- // ? await getWorkerDeploymentFromWorker(prisma, workerId)
43- // : run.runtimeEnvironment.type === "DEVELOPMENT"
44- // ? await getMostRecentWorker(prisma, run.runtimeEnvironmentId)
45- // : await getWorkerFromCurrentlyPromotedDeployment(prisma, run.runtimeEnvironmentId);
39+ const version = await determineEngineVersion ( { environment } ) ;
4640
47- if ( environment . project . engine === RunEngineVersion . V1 ) {
48- return await this . callV1 ( taskId , environment , body , options ) ;
41+ switch ( version ) {
42+ case "V1" : {
43+ return await this . callV1 ( taskId , environment , body , options ) ;
44+ }
45+ case "V2" : {
46+ return await this . callV2 ( taskId , environment , body , options ) ;
47+ }
4948 }
50-
51- if ( environment . type === RuntimeEnvironmentType . DEVELOPMENT ) {
52- return await this . callV1 ( taskId , environment , body , options ) ;
53- }
54-
55- //todo Additional checks
56- /*
57- - If the `triggerVersion` is 3.2 or higher AND the project has engine V2, we will use the run engine.
58- - Add an `engine` column to `Project` in the database.
59-
60- Add `engine` to the trigger.config file. It would default to "V1" for now, but you can set it to V2.
61-
62- You run `npx trigger.dev@latest deploy` with config v2.
63- - Create BackgroundWorker with `engine`: `v2`.
64- - Set the `project` `engine` column to `v2`.
65-
66- You run `npx trigger.dev@latest dev` with config v2
67- - Create BackgroundWorker with `engine`: `v2`.
68- - Set the `project` `engine` column to `v2`.
69-
70- When triggering
71- - triggerAndWait we can lookup the BackgroundWorker easily, and get the engine.
72- - No locked version: lookup the BackgroundWorker via the Deployment/latest dev BW
73- */
74-
75- return await this . callV2 ( taskId , environment , body , options ) ;
7649 } ) ;
7750 }
7851
0 commit comments