@@ -8,7 +8,9 @@ import type { PrismaClientOrTransaction } from "~/db.server";
88import type { AuthenticatedEnvironment } from "~/services/apiAuth.server" ;
99import { ServiceValidationError } from "./baseService.server" ;
1010import { FailDeploymentService } from "./failDeployment.server" ;
11- import { resolveComputeAccess } from "../regionAccess.server" ;
11+ import { resolveComputeAccess , resolveEffectiveDefaultWorkerGroupId } from "../regionAccess.server" ;
12+ import { FEATURE_FLAG } from "../featureFlags" ;
13+ import { makeFlag } from "../featureFlags.server" ;
1214
1315type TemplateCreationMode = "required" | "shadow" | "skip" ;
1416
@@ -56,7 +58,7 @@ export class ComputeTemplateCreationService {
5658 prisma : PrismaClientOrTransaction ;
5759 writer ?: WritableStreamDefaultWriter ;
5860 } ) : Promise < void > {
59- const mode = await this . resolveMode ( options . projectId , options . prisma ) ;
61+ const mode = await this . resolveMode ( options . authenticatedEnv , options . prisma ) ;
6062
6163 if ( mode === "skip" ) {
6264 return ;
@@ -134,19 +136,17 @@ export class ComputeTemplateCreationService {
134136 }
135137
136138 async resolveMode (
137- projectId : string ,
139+ authenticatedEnv : AuthenticatedEnvironment ,
138140 prisma : PrismaClientOrTransaction
139141 ) : Promise < TemplateCreationMode > {
140142 if ( ! this . client ) {
141143 return "skip" ;
142144 }
143145
144146 const project = await prisma . project . findFirst ( {
145- where : { id : projectId } ,
147+ where : { id : authenticatedEnv . projectId } ,
146148 select : {
147- defaultWorkerGroup : {
148- select : { workloadType : true } ,
149- } ,
149+ defaultWorkerGroupId : true ,
150150 organization : {
151151 select : { featureFlags : true } ,
152152 } ,
@@ -157,7 +157,24 @@ export class ComputeTemplateCreationService {
157157 return "skip" ;
158158 }
159159
160- if ( project . defaultWorkerGroup ?. workloadType === "MICROVM" ) {
160+ // Resolve the region this env actually deploys to: env default -> project default -> global default.
161+ const globalDefaultWorkerGroupId = await makeFlag ( prisma ) ( {
162+ key : FEATURE_FLAG . defaultWorkerInstanceGroupId ,
163+ } ) ;
164+ const effectiveDefaultWorkerGroupId = resolveEffectiveDefaultWorkerGroupId ( {
165+ environmentDefaultWorkerGroupId : authenticatedEnv . defaultWorkerGroupId ,
166+ projectDefaultWorkerGroupId : project . defaultWorkerGroupId ,
167+ globalDefaultWorkerGroupId,
168+ } ) ;
169+
170+ const defaultWorkerGroup = effectiveDefaultWorkerGroupId
171+ ? await prisma . workerInstanceGroup . findFirst ( {
172+ where : { id : effectiveDefaultWorkerGroupId } ,
173+ select : { workloadType : true } ,
174+ } )
175+ : null ;
176+
177+ if ( defaultWorkerGroup ?. workloadType === "MICROVM" ) {
161178 return "required" ;
162179 }
163180
0 commit comments