feat(calendar): add error tracking with attempts to SelectedCalendar (#21326)

Co-authored-by: [email protected] <[email protected]>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: Omar López <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-05-23 16:38:54 +00:00
1 parent bca46228e7
commit 3a8e40d029
7 files changed
+146 -32

No files matched your search

@@ -167,13 +167,35 @@ export class SelectedCalendarRepository {
},
// RN we only support google calendar subscriptions for now
integration: "google_calendar",
// We skip retrying calendars that have errored
error: null,
OR: [
// Either is a calendar pending to be watched
{ googleChannelExpiration: null },
// Or is a calendar that is about to expire
{ googleChannelExpiration: { lt: tomorrowTimestamp } },
AND: [
{
OR: [
// Either is a calendar that has not errored
{ error: null },
// Or is a calendar that has errored but has not reached max attempts
{
error: { not: null },
watchAttempts: {
lt: {
// Using ts-ignore instead of ts-expect-error because I am seeing conflicting errors in CI. In one case ts-expect-error fails with `Unused '@ts-expect-error' directive.`
// Removing ts-expect-error fails in another case that _ref isn't defined
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
_ref: "maxAttempts",
_container: "SelectedCalendar",
},
},
},
],
},
{
OR: [
// Either is a calendar pending to be watched
{ googleChannelExpiration: null },
// Or is a calendar that is about to expire
{ googleChannelExpiration: { lt: tomorrowTimestamp } },
],
},
],
},
});
@@ -188,19 +210,43 @@ export class SelectedCalendarRepository {
// RN we only support google calendar subscriptions for now
integration: "google_calendar",
googleChannelExpiration: { not: null },
user: {
teams: {
every: {
team: {
features: {
none: {
featureId: "calendar-cache",
AND: [
{
OR: [
// Either is a calendar that has not errored during unwatch
{ error: null },
// Or is a calendar that has errored during unwatch but has not reached max attempts
{
error: { not: null },
unwatchAttempts: {
lt: {
// Using ts-ignore instead of ts-expect-error because I am seeing conflicting errors in CI. In one case ts-expect-error fails with `Unused '@ts-expect-error' directive.`
// Removing ts-expect-error fails in another case that _ref isn't defined
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
_ref: "maxAttempts",
_container: "SelectedCalendar",
},
},
},
],
},
{
user: {
teams: {
every: {
team: {
features: {
none: {
featureId: "calendar-cache",
},
},
},
},
},
},
},
},
],
};
// If calendar cache is disabled globally, we skip team features and unwatch all subscriptions
const nextBatch = await prisma.selectedCalendar.findMany({
@@ -351,4 +397,36 @@ export class SelectedCalendarRepository {
data,
});
}
static async setErrorInWatching({ id, error }: { id: string; error: string }) {
await SelectedCalendarRepository.updateById(id, {
error,
lastErrorAt: new Date(),
watchAttempts: { increment: 1 },
});
}
static async setErrorInUnwatching({ id, error }: { id: string; error: string }) {
await SelectedCalendarRepository.updateById(id, {
error,
lastErrorAt: new Date(),
unwatchAttempts: { increment: 1 },
});
}
static async removeWatchingError({ id }: { id: string }) {
await SelectedCalendarRepository.updateById(id, {
error: null,
lastErrorAt: null,
watchAttempts: 0,
});
}
static async removeUnwatchingError({ id }: { id: string }) {
await SelectedCalendarRepository.updateById(id, {
error: null,
lastErrorAt: null,
unwatchAttempts: 0,
});
}
}