Skip to content

Commit 97ef639

Browse files
1stvampTrigger.dev RepoOps
authored andcommitted
fix(webapp): resolve a project's default worker group for template prebuild eligibility
Template prebuild eligibility now resolves a project's default worker group the same way triggering does, including the fallback to the global default group. Mono-RevId: 8ad53cce26c26034dc834b97f950fc70cfda7f9a
1 parent 58c358e commit 97ef639

2 files changed

Lines changed: 41 additions & 9 deletions

File tree

‎apps/webapp/app/v3/services/templatePrebuild.server.ts‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { makeFlag } from "~/v3/featureFlags.server";
1313
import { globalFlagsRegistry } from "~/v3/globalFlagsRegistry.server";
1414
import { machinePresetFromName } from "~/v3/machinePresets.server";
1515
import { resolveComputeAccess } from "~/v3/regionAccess.server";
16+
import { WorkerGroupService } from "~/v3/services/worker/workerGroupService.server";
1617
import {
1718
backingForQueue,
1819
selfBackingWorkerGroups,
@@ -255,22 +256,27 @@ export class TemplatePrebuildService {
255256
}> {
256257
const project = await this.prisma.project.findFirst({
257258
where: { id: projectId },
258-
select: {
259-
defaultWorkerGroup: { select: { workloadType: true, masterQueue: true } },
260-
organization: { select: { id: true, featureFlags: true } },
261-
},
259+
select: { organization: { select: { id: true, featureFlags: true } } },
262260
});
263261

264262
if (!project) {
265263
return { mode: "skip", reason: "no-project", diagnostics: {} };
266264
}
267265

266+
// As on the trigger path, a project without its own default group uses the global one.
267+
const defaultWorkerGroup = await new WorkerGroupService({
268+
prisma: this.prisma,
269+
}).getDefaultWorkerGroupForProject({ projectId });
270+
268271
const diagnostics: EligibilityDiagnostics = {
269272
organizationId: project.organization.id,
270-
workloadType: project.defaultWorkerGroup?.workloadType,
271-
masterQueue: project.defaultWorkerGroup?.masterQueue,
273+
workloadType: defaultWorkerGroup?.workloadType,
274+
masterQueue: defaultWorkerGroup?.masterQueue,
272275
};
273-
const reason = await this.eligibility(project, diagnostics);
276+
const reason = await this.eligibility(
277+
{ ...project, defaultWorkerGroup: defaultWorkerGroup ?? null },
278+
diagnostics
279+
);
274280
diagnostics.eligible = reason !== "none";
275281
if (!this.config.url) {
276282
return { mode: "skip", reason: "no-builder", diagnostics };

‎apps/webapp/test/engine/triggerTask.templateKey.test.ts‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import { workerQueueForBirth } from "~/runEngine/concerns/workerQueueAssignment.
3737
import { DefaultQueueManager } from "~/runEngine/concerns/queues.server";
3838
import type { RunEngine } from "~/v3/runEngine.server";
3939
import { RedisTaskMetadataCache } from "~/services/taskMetadataCache.server";
40+
import { FEATURE_FLAG } from "~/v3/featureFlags";
41+
import { makeSetFlag } from "~/v3/featureFlags.server";
4042
import { ChangeCurrentDeploymentService } from "~/v3/services/changeCurrentDeployment.server";
4143
import { TemplatePrebuildService } from "~/v3/services/templatePrebuild.server";
4244
import {
@@ -463,7 +465,7 @@ describe("a mixed-runtime group as its region's compute backing", () => {
463465
// One CONTAINER group carries both runtimes; the old MICROVM group is hidden unless asked.
464466
async function setupRegion(
465467
prisma: PrismaClient,
466-
options: { migrated: boolean; visibleMicrovm?: boolean }
468+
options: { migrated: boolean; visibleMicrovm?: boolean; globalDefault?: boolean }
467469
) {
468470
const environment = await setupAuthenticatedEnvironment(prisma, "PRODUCTION");
469471
const group = (masterQueue: string, workloadType: "CONTAINER" | "MICROVM", hidden: boolean) =>
@@ -480,10 +482,17 @@ describe("a mixed-runtime group as its region's compute backing", () => {
480482
});
481483
const mixed = await group("cme-mixed", "CONTAINER", false);
482484
await group("us-east-1-mvm", "MICROVM", !options.visibleMicrovm);
485+
// With globalDefault, the project has no default group and falls back to the global one.
483486
await prisma.project.update({
484487
where: { id: environment.project.id },
485-
data: { defaultWorkerGroupId: mixed.id },
488+
data: { defaultWorkerGroupId: options.globalDefault ? null : mixed.id },
486489
});
490+
if (options.globalDefault) {
491+
await makeSetFlag(prisma)({
492+
key: FEATURE_FLAG.defaultWorkerInstanceGroupId,
493+
value: mixed.id,
494+
});
495+
}
487496
await prisma.organization.update({
488497
where: { id: environment.organization.id },
489498
data: { featureFlags: { computeMigrationEnabled: options.migrated } },
@@ -575,6 +584,23 @@ describe("a mixed-runtime group as its region's compute backing", () => {
575584
}
576585
);
577586

587+
containerTest(
588+
"a migrated org without a project default group is eligible through the global default",
589+
async ({ prisma, redisOptions }) => {
590+
db.client = prisma;
591+
const { environment, mixed } = await setupRegion(prisma, {
592+
migrated: true,
593+
globalDefault: true,
594+
});
595+
596+
expect(await prebuildMode(prisma, environment.project.id, [mixed.id])).toEqual({
597+
mode: "shadow",
598+
reason: "migrated",
599+
});
600+
expect(await birthQueue(prisma, redisOptions, environment, [mixed.id], KEY)).toBe(COMPUTE);
601+
}
602+
);
603+
578604
containerTest(
579605
"a migrated org's keyless run on a listed group stays on containers",
580606
async ({ prisma, redisOptions }) => {

0 commit comments

Comments
 (0)