From 4d192ee3283aa3b12a4ac1a7cbd356cfcdd7773a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20L=C3=B3pez?= Date: Tue, 17 Dec 2024 21:04:08 -0700 Subject: [PATCH] fix: single rejection caused cache cron to fail (#18239) --- packages/features/calendar-cache/api/cron.ts | 15 ++------------- .../lib/server/repository/selectedCalendar.ts | 13 ++++--------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/packages/features/calendar-cache/api/cron.ts b/packages/features/calendar-cache/api/cron.ts index 63faac20c6..ffa9cf738f 100644 --- a/packages/features/calendar-cache/api/cron.ts +++ b/packages/features/calendar-cache/api/cron.ts @@ -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(), }; }); diff --git a/packages/lib/server/repository/selectedCalendar.ts b/packages/lib/server/repository/selectedCalendar.ts index 7c851a0c71..ed0e00ed20 100644 --- a/packages/lib/server/repository/selectedCalendar.ts +++ b/packages/lib/server/repository/selectedCalendar.ts @@ -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"; @@ -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: { @@ -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,