Skip to content

Commit

Permalink
fix: single rejection caused cache cron to fail (#18239)
Browse files Browse the repository at this point in the history
  • Loading branch information
zomars authored Dec 18, 2024
1 parent 63013d4 commit 4d192ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
15 changes: 2 additions & 13 deletions packages/features/calendar-cache/api/cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,11 @@ const handleCalendarsToWatch = async () => {
// This cron is used to activate and renew calendar subcriptions
const handler = defaultResponder(async (request: NextApiRequest) => {
validateRequest(request);
const [watchedResult, unwatchedResult] = await Promise.all([
handleCalendarsToWatch(),
handleCalendarsToUnwatch(),
]);
await Promise.allSettled([handleCalendarsToWatch(), handleCalendarsToUnwatch()]);

// TODO: Credentials can be installed on a whole team, check for selected calendars on the team
return {
succeededAt: new Date().toISOString(),
watched: {
successful: watchedResult.filter((x) => x.status === "fulfilled").length,
failed: watchedResult.filter((x) => x.status === "rejected").length,
},
unwatched: {
successful: unwatchedResult.filter((x) => x.status === "fulfilled").length,
failed: unwatchedResult.filter((x) => x.status === "rejected").length,
},
executedAt: new Date().toISOString(),
};
});

Expand Down
13 changes: 4 additions & 9 deletions packages/lib/server/repository/selectedCalendar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Prisma } from "@prisma/client";

import { FeaturesRepository } from "@calcom/features/flags/features.repository";
import { prisma } from "@calcom/prisma";
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";

Expand Down Expand Up @@ -64,12 +63,7 @@ export class SelectedCalendarRepository {
// RN we only support google calendar subscriptions for now
integration: "google_calendar",
googleChannelExpiration: { not: null },
};
const featureRepo = new FeaturesRepository();
const calendarCache = await featureRepo.checkIfFeatureIsEnabledGlobally("calendar-cache");
// If calendar cache is disabled globally, we skip team features and unwatch all subscriptions
if (!calendarCache) {
where.user = {
user: {
teams: {
every: {
team: {
Expand All @@ -81,8 +75,9 @@ export class SelectedCalendarRepository {
},
},
},
};
}
},
};
// If calendar cache is disabled globally, we skip team features and unwatch all subscriptions
const nextBatch = await prisma.selectedCalendar.findMany({
take: limit,
where,
Expand Down

0 comments on commit 4d192ee

Please sign in to comment.