Skip to content

Commit 77cc952

Browse files
committed
Check schedule limit properly. Improve some structure
1 parent 4c9a4d9 commit 77cc952

File tree

3 files changed

+26
-43
lines changed

3 files changed

+26
-43
lines changed

apps/webapp/app/presenters/v3/LimitsPresenter.server.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { createRedisRateLimitClient, type Duration } from "~/services/rateLimite
1111
import { BasePresenter } from "./basePresenter.server";
1212
import { singleton } from "~/utils/singleton";
1313
import { logger } from "~/services/logger.server";
14+
import { CheckScheduleService } from "~/v3/services/checkSchedule.server";
1415

1516
// Create a singleton Redis client for rate limit queries
1617
const rateLimitRedisClient = singleton("rateLimitQueryRedisClient", () =>
@@ -64,13 +65,10 @@ export type LimitsResult = {
6465
branches: QuotaInfo | null;
6566
logRetentionDays: QuotaInfo | null;
6667
realtimeConnections: QuotaInfo | null;
68+
batchProcessingConcurrency: QuotaInfo;
6769
devQueueSize: QuotaInfo;
6870
deployedQueueSize: QuotaInfo;
6971
};
70-
batchConcurrency: {
71-
limit: number;
72-
source: "default" | "override";
73-
};
7472
features: {
7573
hasStagingEnvironment: FeatureInfo;
7674
support: FeatureInfo;
@@ -131,14 +129,10 @@ export class LimitsPresenter extends BasePresenter {
131129
? "override"
132130
: "default";
133131

134-
// Get schedule count for this org (via project relation which has an index)
135-
//TODO we should change the way we count these and use the ScheduleListPresenter method
136-
const scheduleCount = await this._replica.taskSchedule.count({
137-
where: {
138-
project: {
139-
organizationId,
140-
},
141-
},
132+
// Get schedule count for this org
133+
const scheduleCount = await CheckScheduleService.getUsedSchedulesCount({
134+
prisma: this._replica,
135+
projectId,
142136
});
143137

144138
// Get alert channel count for this org
@@ -277,6 +271,15 @@ export class LimitsPresenter extends BasePresenter {
277271
isUpgradable: true,
278272
}
279273
: null,
274+
batchProcessingConcurrency: {
275+
name: "Batch processing concurrency",
276+
description: "Controls how many batch items can be processed simultaneously.",
277+
limit: batchConcurrencyConfig.processingConcurrency,
278+
currentUsage: 0,
279+
source: batchConcurrencySource,
280+
canExceed: true,
281+
isUpgradable: true,
282+
},
280283
devQueueSize: {
281284
name: "Dev queue size",
282285
description: "Maximum pending runs in development environments",
@@ -292,10 +295,6 @@ export class LimitsPresenter extends BasePresenter {
292295
source: organization.maximumDeployedQueueSize ? "override" : "default",
293296
},
294297
},
295-
batchConcurrency: {
296-
limit: batchConcurrencyConfig.processingConcurrency,
297-
source: batchConcurrencySource,
298-
},
299298
features: {
300299
hasStagingEnvironment: {
301300
name: "Staging environment",

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.limits/route.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ export default function Page() {
161161
{/* Quotas Section */}
162162
<QuotasSection
163163
quotas={data.quotas}
164-
batchConcurrency={data.batchConcurrency}
165164
isOnTopPlan={data.isOnTopPlan}
166165
billingPath={organizationBillingPath(organization)}
167166
/>
@@ -483,12 +482,10 @@ function RateLimitConfigDisplay({ config }: { config: RateLimitInfo["config"] })
483482

484483
function QuotasSection({
485484
quotas,
486-
batchConcurrency,
487485
isOnTopPlan,
488486
billingPath,
489487
}: {
490488
quotas: LimitsResult["quotas"];
491-
batchConcurrency: LimitsResult["batchConcurrency"];
492489
isOnTopPlan: boolean;
493490
billingPath: string;
494491
}) {
@@ -506,16 +503,8 @@ function QuotasSection({
506503
if (quotas.realtimeConnections) quotaRows.push(quotas.realtimeConnections);
507504
if (quotas.logRetentionDays) quotaRows.push(quotas.logRetentionDays);
508505

509-
// Include batch processing concurrency as a quota row
510-
quotaRows.push({
511-
name: "Batch processing concurrency",
512-
description: "Controls how many batch items can be processed simultaneously.",
513-
limit: batchConcurrency.limit,
514-
currentUsage: 0,
515-
source: batchConcurrency.source,
516-
canExceed: true, // Allow contact us on top plan, view plans otherwise
517-
isUpgradable: true,
518-
});
506+
// Include batch processing concurrency
507+
quotaRows.push(quotas.batchProcessingConcurrency);
519508

520509
// Add queue size quotas if set
521510
if (quotas.devQueueSize.limit !== null) quotaRows.push(quotas.devQueueSize);

apps/webapp/app/v3/services/checkSchedule.server.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class CheckScheduleService extends BaseService {
9292
const limit = await getLimit(project.organizationId, "schedules", 100_000_000);
9393
const schedulesCount = await CheckScheduleService.getUsedSchedulesCount({
9494
prisma: this._prisma,
95-
environments: project.environments,
95+
projectId,
9696
});
9797

9898
if (schedulesCount >= limit) {
@@ -105,26 +105,21 @@ export class CheckScheduleService extends BaseService {
105105

106106
static async getUsedSchedulesCount({
107107
prisma,
108-
environments,
108+
projectId,
109109
}: {
110110
prisma: PrismaClientOrTransaction;
111-
environments: { id: string; type: RuntimeEnvironmentType; archivedAt: Date | null }[];
111+
projectId: string;
112112
}) {
113-
const deployedEnvironments = environments.filter(
114-
(env) => env.type !== "DEVELOPMENT" && !env.archivedAt
115-
);
116-
const schedulesCount = await prisma.taskScheduleInstance.count({
113+
return await prisma.taskScheduleInstance.count({
117114
where: {
118-
environmentId: {
119-
in: deployedEnvironments.map((env) => env.id),
115+
projectId,
116+
environment: {
117+
type: {
118+
not: "DEVELOPMENT",
119+
},
120120
},
121121
active: true,
122-
taskSchedule: {
123-
active: true,
124-
},
125122
},
126123
});
127-
128-
return schedulesCount;
129124
}
130125
}

0 commit comments

Comments
 (0)