From f6037595e133bbd4ee41eea55ea651af96475319 Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Thu, 4 Jul 2024 18:44:32 +0100 Subject: [PATCH] Use the new schedule limit --- .../v3/services/upsertTaskSchedule.server.ts | 24 +++++++++---------- packages/database/prisma/schema.prisma | 1 + 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/apps/webapp/app/v3/services/upsertTaskSchedule.server.ts b/apps/webapp/app/v3/services/upsertTaskSchedule.server.ts index b46fd17a9..c824a6ccb 100644 --- a/apps/webapp/app/v3/services/upsertTaskSchedule.server.ts +++ b/apps/webapp/app/v3/services/upsertTaskSchedule.server.ts @@ -10,6 +10,7 @@ import cronstrue from "cronstrue"; import { calculateNextScheduledTimestamp } from "../utils/calculateNextSchedule.server"; import { getTimezones } from "~/utils/timezones.server"; import { env } from "~/env.server"; +import { getLimit } from "~/services/platform.v3.server"; export type UpsertTaskScheduleServiceOptions = UpsertSchedule; @@ -67,32 +68,29 @@ export class UpsertTaskScheduleService extends BaseService { //if creating a schedule, check they're under the limits if (!schedule.friendlyId) { //check they're within their limit - const limits = await this._prisma.organization.findFirst({ - select: { - maximumSchedulesLimit: true, - }, + const project = await this._prisma.project.findFirst({ where: { - projects: { - some: { - id: projectId, - }, - }, + id: projectId, + }, + select: { + organizationId: true, }, }); - if (!limits) { - throw new ServiceValidationError("Organization not found"); + if (!project) { + throw new ServiceValidationError("Project not found"); } + const limit = await getLimit(project.organizationId, "schedules", 500); const schedulesCount = await this._prisma.taskSchedule.count({ where: { projectId, }, }); - if (schedulesCount >= limits.maximumSchedulesLimit) { + if (schedulesCount >= limit) { throw new ServiceValidationError( - `You have created ${schedulesCount}/${limits.maximumSchedulesLimit} schedules so you'll need to increase your limits or delete some schedules. Increase your limits by contacting support.` + `You have created ${schedulesCount}/${limit} schedules so you'll need to increase your limits or delete some schedules. Increase your limits by contacting support.` ); } } diff --git a/packages/database/prisma/schema.prisma b/packages/database/prisma/schema.prisma index a9138320a..06d0d34b2 100644 --- a/packages/database/prisma/schema.prisma +++ b/packages/database/prisma/schema.prisma @@ -111,6 +111,7 @@ model Organization { maximumExecutionTimePerRunInMs Int @default(900000) // 15 minutes maximumConcurrencyLimit Int @default(10) + /// This is deprecated and will be removed in the future maximumSchedulesLimit Int @default(5) createdAt DateTime @default(now())