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

+16 -10
View File
@@ -68,7 +68,8 @@ const handleCalendarsToUnwatch = async () => {
// So we don't retry on next cron run
// FIXME: There could actually be multiple calendars with the same externalId and thus we need to technically update error for all of them
await SelectedCalendarRepository.updateById(id, {
await SelectedCalendarRepository.setErrorInUnwatching({
id,
error: "Missing credentialId",
});
log.error("no credentialId for SelectedCalendar: ", id);
@@ -78,26 +79,30 @@ const handleCalendarsToUnwatch = async () => {
try {
const cc = await CalendarCache.initFromCredentialId(credentialId);
await cc.unwatchCalendar({ calendarId: externalId, eventTypeIds });
await SelectedCalendarRepository.removeUnwatchingError({ id });
} catch (error) {
let errorMessage = "Unknown error";
if (error instanceof Error) {
errorMessage = error.message;
}
log.error(
"Error unwatching calendar: ",
`Error unwatching calendar ${externalId}`,
safeStringify({
selectedCalendarId: id,
error: errorMessage,
})
);
await SelectedCalendarRepository.updateById(id, {
error: `Error unwatching calendar: ${errorMessage}`,
await SelectedCalendarRepository.setErrorInUnwatching({
id,
error: `${errorMessage}`,
});
}
}
)
);
log.info(`Processed ${result.length} calendars for unwatching`);
result.forEach(logRejected);
return result;
};
@@ -110,9 +115,7 @@ const handleCalendarsToWatch = async () => {
async ([externalId, { credentialId, eventTypeIds, id }]) => {
if (!credentialId) {
// So we don't retry on next cron run
await SelectedCalendarRepository.updateById(id, {
error: "Missing credentialId",
});
await SelectedCalendarRepository.setErrorInWatching({ id, error: "Missing credentialId" });
log.error("no credentialId for SelectedCalendar: ", id);
return;
}
@@ -120,25 +123,28 @@ const handleCalendarsToWatch = async () => {
try {
const cc = await CalendarCache.initFromCredentialId(credentialId);
await cc.watchCalendar({ calendarId: externalId, eventTypeIds });
await SelectedCalendarRepository.removeWatchingError({ id });
} catch (error) {
let errorMessage = "Unknown error";
if (error instanceof Error) {
errorMessage = error.message;
}
log.error(
"Error watching calendar: ",
`Error watching calendar ${externalId}`,
safeStringify({
selectedCalendarId: id,
error: errorMessage,
})
);
await SelectedCalendarRepository.updateById(id, {
error: `Error watching calendar: ${errorMessage}`,
await SelectedCalendarRepository.setErrorInWatching({
id,
error: `${errorMessage}`,
});
}
}
)
);
log.info(`Processed ${result.length} calendars for watching`);
result.forEach(logRejected);
return result;
};