Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .server-changes/scope-declarative-schedule-sync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
area: webapp
type: improvement
---

Make background worker registration cheaper for projects with many scheduled tasks by scoping declarative schedule reconciliation to the current environment and dropping redundant schedule lookups.
2 changes: 2 additions & 0 deletions apps/webapp/app/v3/services/checkSchedule.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,14 @@ export class CheckScheduleService extends BaseService {
projectId,
active: true,
environment: {
projectId,
type: {
not: "DEVELOPMENT",
},
archivedAt: null,
},
taskSchedule: {
projectId,
active: true,
},
},
Expand Down
29 changes: 17 additions & 12 deletions apps/webapp/app/v3/services/createBackgroundWorker.server.ts
Comment thread
ericallam marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,21 @@ export async function syncDeclarativeSchedules(
where: {
type: "DECLARATIVE",
projectId: environment.projectId,
instances: {
some: {
environmentId: environment.id,
},
},
Comment thread
ericallam marked this conversation as resolved.
},
include: {
instances: true,
select: {
id: true,
friendlyId: true,
taskIdentifier: true,
instances: {
select: {
environmentId: true,
},
},
},
});

Expand Down Expand Up @@ -764,16 +776,9 @@ export async function syncDeclarativeSchedules(

//Delete instances for this environment
//Delete schedules that have no instances left
const potentiallyDeletableSchedules = await prisma.taskSchedule.findMany({
where: {
id: {
in: boundedIn(Array.from(missingSchedules)),
},
},
include: {
instances: true,
},
});
const potentiallyDeletableSchedules = existingDeclarativeSchedules.filter((schedule) =>
missingSchedules.has(schedule.id)
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const scheduleIdsToDelete: string[] = [];
const scheduleIdsToDetachFromEnvironment: string[] = [];
Expand Down
Loading