Skip to content

Commit 7484611

Browse files
carderneTrigger.dev RepoOps
authored andcommitted
feat(billing): admin override for an org's dev concurrency
Mono-RevId: 6988801016b440d9ca54a93c225e9ec058898706
1 parent 3c68951 commit 7484611

3 files changed

Lines changed: 38 additions & 6 deletions

File tree

‎apps/webapp/app/routes/admin.api.v1.orgs.$organizationId.concurrency.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const ParamsSchema = z.object({
1313
});
1414

1515
const RequestBodySchema = z.object({
16-
organization: z.number(),
16+
organization: z.number().optional(),
1717
development: z.number().optional(),
1818
staging: z.number().optional(),
1919
production: z.number().optional(),

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function reconcilingPush(prisma: PrismaClient, push: PushEnvLimit): PushE
5050
}
5151

5252
export type ConcurrencyLimits = {
53-
organization: number;
53+
organization?: number;
5454
development?: number;
5555
staging?: number;
5656
production?: number;
@@ -121,10 +121,12 @@ export async function setOrgConcurrencyLimits(
121121
{ types: ["PRODUCTION"] as const, limit: limits.production },
122122
];
123123

124-
await prisma.organization.update({
125-
where: { id: organizationId },
126-
data: { maximumConcurrencyLimit: limits.organization },
127-
});
124+
if (limits.organization !== undefined) {
125+
await prisma.organization.update({
126+
where: { id: organizationId },
127+
data: { maximumConcurrencyLimit: limits.organization },
128+
});
129+
}
128130

129131
for (const { types, limit } of byType) {
130132
if (!limit) continue;

‎apps/webapp/test/orgPlanProvisioning.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,36 @@ describe("reconcilingPush", () => {
201201
});
202202

203203
describe("org concurrency limits", () => {
204+
postgresTest(
205+
"updates dev roots and branches without changing other limits",
206+
async ({ prisma }) => {
207+
const { organization, project, envs } = await seedOrg(prisma);
208+
const branch = await createRuntimeEnvironment(prisma, {
209+
projectId: project.id,
210+
organizationId: organization.id,
211+
type: "DEVELOPMENT",
212+
slug: uniqueId("dev-branch"),
213+
});
214+
await prisma.runtimeEnvironment.update({
215+
where: { id: branch.id },
216+
data: { parentEnvironmentId: envs.dev.id },
217+
});
218+
219+
await setOrgConcurrencyLimits(organization.id, { development: 80 }, prisma);
220+
221+
const limits = await prisma.runtimeEnvironment.findMany({
222+
where: { organizationId: organization.id },
223+
select: { id: true, maximumConcurrencyLimit: true },
224+
});
225+
const byId = new Map(limits.map((env) => [env.id, env.maximumConcurrencyLimit]));
226+
expect(byId.get(envs.dev.id)).toBe(80);
227+
expect(byId.get(branch.id)).toBe(80);
228+
expect(byId.get(envs.running.id)).toBe(envs.running.maximumConcurrencyLimit);
229+
const org = await prisma.organization.findFirstOrThrow({ where: { id: organization.id } });
230+
expect(org.maximumConcurrencyLimit).toBe(organization.maximumConcurrencyLimit);
231+
}
232+
);
233+
204234
postgresTest("stores limits per env type and pushes the stored values", async ({ prisma }) => {
205235
const { organization, envs } = await seedOrg(prisma);
206236
const { project: v2Project } = await createTestOrgProjectWithMember(prisma);

0 commit comments

Comments
 (0)