Skip to content

Commit

Permalink
fix: Add jitter when Outlook requests are throttled (#16484)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeauyeung authored Sep 4, 2024
1 parent 9ef5320 commit 2e36cad
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/app-store/office365calendar/lib/CalendarService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,13 @@ export default class Office365CalendarService implements Calendar {
const calendarSelectParams = "$select=showAs,start,end";

try {
const selectedCalendarIds = selectedCalendars
.filter((e) => e.integration === this.integrationName)
.map((e) => e.externalId)
.filter(Boolean);
const selectedCalendarIds = selectedCalendars.reduce((calendarIds, calendar) => {
if (calendar.integration === this.integrationName && calendar.externalId)
calendarIds.push(calendar.externalId);

return calendarIds;
}, [] as string[]);

if (selectedCalendarIds.length === 0 && selectedCalendars.length > 0) {
// Only calendars of other integrations selected
return Promise.resolve([]);
Expand Down Expand Up @@ -373,6 +376,7 @@ export default class Office365CalendarService implements Calendar {
maxRetries: number,
retryCount = 0
): Promise<IBatchResponse> => {
const getRandomness = () => Number(Math.random().toFixed(3));
let retryAfterTimeout = 0;
if (retryCount >= maxRetries) {
return { responses: settledPromises };
Expand All @@ -394,7 +398,7 @@ export default class Office365CalendarService implements Calendar {
}

// Await certain time from retry-after header
await new Promise((r) => setTimeout(r, retryAfterTimeout));
await new Promise((r) => setTimeout(r, retryAfterTimeout + getRandomness()));

const newResponses = await this.apiGraphBatchCall(failedRequest);
let newResponseBody = await handleErrorsJson<IBatchResponse | string>(newResponses);
Expand Down

0 comments on commit 2e36cad

Please sign in to comment.