Skip to content

Commit 28135d5

Browse files
committed
Change how we count schedules towards your limits
1 parent d412b82 commit 28135d5

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { displayableEnvironment } from "~/models/runtimeEnvironment.server";
55
import { getCurrentPlan, getLimit, getLimits } from "~/services/platform.v3.server";
66
import { calculateNextScheduledTimestamp } from "~/v3/utils/calculateNextSchedule.server";
77
import { BasePresenter } from "./basePresenter.server";
8+
import { CheckScheduleService } from "~/v3/services/checkSchedule.server";
89

910
type ScheduleListOptions = {
1011
projectId: string;
@@ -86,10 +87,9 @@ export class ScheduleListPresenter extends BasePresenter {
8687
},
8788
});
8889

89-
const schedulesCount = await this._prisma.taskSchedule.count({
90-
where: {
91-
projectId,
92-
},
90+
const schedulesCount = await CheckScheduleService.getUsedSchedulesCount({
91+
prisma: this._replica,
92+
environments: project.environments,
9393
});
9494

9595
//get all possible scheduled tasks

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { BaseService, ServiceValidationError } from "./baseService.server";
44
import { getLimit } from "~/services/platform.v3.server";
55
import { getTimezones } from "~/utils/timezones.server";
66
import { env } from "~/env.server";
7+
import { type PrismaClientOrTransaction, type RuntimeEnvironmentType } from "@trigger.dev/database";
78

89
type Schedule = {
910
cron: string;
@@ -90,4 +91,27 @@ export class CheckScheduleService extends BaseService {
9091
}
9192
}
9293
}
94+
95+
static async getUsedSchedulesCount({
96+
prisma,
97+
environments,
98+
}: {
99+
prisma: PrismaClientOrTransaction;
100+
environments: { id: string; type: RuntimeEnvironmentType }[];
101+
}) {
102+
const deployedEnvironments = environments.filter((env) => env.type !== "DEVELOPMENT");
103+
const schedulesCount = await prisma.taskScheduleInstance.count({
104+
where: {
105+
environmentId: {
106+
in: deployedEnvironments.map((env) => env.id),
107+
},
108+
active: true,
109+
taskSchedule: {
110+
active: true,
111+
},
112+
},
113+
});
114+
115+
return schedulesCount;
116+
}
93117
}

0 commit comments

Comments
 (0)