-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Support multiple round-robin host selection #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -670,9 +670,11 @@ async function handler( | |
|
|
||
| const luckyUsers: typeof users = []; | ||
|
|
||
| // Get number of hosts to select from event metadata, default to 1 | ||
| const numberOfHostsToSelect = eventType.metadata?.multipleRoundRobinHosts || 1; | ||
| // loop through all non-fixed hosts and get the lucky users | ||
| // This logic doesn't run when contactOwner is used because in that case, luckUsers.length === 1 | ||
| while (luckyUserPool.length > 0 && luckyUsers.length < 1 /* TODO: Add variable */) { | ||
| while (luckyUserPool.length > 0 && luckyUsers.length < numberOfHostsToSelect) { | ||
| const freeUsers = luckyUserPool.filter( | ||
| (user) => !luckyUsers.concat(notAvailableLuckyUsers).find((existing) => existing.id === user.id) | ||
| ); | ||
|
|
@@ -686,7 +688,10 @@ async function handler( | |
| memberId: eventTypeWithUsers.users[0].id ?? null, | ||
| teamId: eventType.teamId, | ||
| }); | ||
| const newLuckyUser = await getLuckyUser({ | ||
| // Check if we need to select multiple hosts | ||
| const numberOfHostsToSelect = eventType.metadata?.multipleRoundRobinHosts || 1; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| const newLuckyUsers = await getLuckyUser({ | ||
|
Comment on lines
+691
to
+694
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bruh |
||
| // find a lucky user that is not already in the luckyUsers array | ||
| availableUsers: freeUsers, | ||
| allRRHosts: ( | ||
|
|
@@ -697,43 +702,54 @@ async function handler( | |
| ).filter((host) => !host.isFixed && userIdsSet.has(host.user.id)), | ||
| eventType, | ||
| routingFormResponse, | ||
| numberOfHostsToSelect, | ||
| }); | ||
|
|
||
| // Handle single vs multiple users being returned | ||
| const newLuckyUser = Array.isArray(newLuckyUsers) ? newLuckyUsers[0] : newLuckyUsers; | ||
| if (!newLuckyUser) { | ||
| break; // prevent infinite loop | ||
|
Comment on lines
703
to
711
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bruh2 |
||
| } | ||
|
|
||
| // Handle both cases - single user and multiple users | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one two three |
||
| const usersToProcess = Array.isArray(newLuckyUsers) ? newLuckyUsers : [newLuckyUser]; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. asdf |
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yoot |
||
| if (req.body.isFirstRecurringSlot && eventType.schedulingType === SchedulingType.ROUND_ROBIN) { | ||
| // for recurring round robin events check if lucky user is available for next slots | ||
| try { | ||
| for ( | ||
| let i = 0; | ||
| i < req.body.allRecurringDates.length && i < req.body.numSlotsToCheckForAvailability; | ||
| i++ | ||
| ) { | ||
| const start = req.body.allRecurringDates[i].start; | ||
| const end = req.body.allRecurringDates[i].end; | ||
|
|
||
| await ensureAvailableUsers( | ||
| { ...eventTypeWithUsers, users: [newLuckyUser] }, | ||
| { | ||
| dateFrom: dayjs(start).tz(reqBody.timeZone).format(), | ||
| dateTo: dayjs(end).tz(reqBody.timeZone).format(), | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. foo |
||
| timeZone: reqBody.timeZone, | ||
| originalRescheduledBooking, | ||
| }, | ||
| loggerWithEventDetails, | ||
| shouldServeCache | ||
| // for recurring round robin events check if lucky users are available for next slots | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. log |
||
| for (const user of usersToProcess) { | ||
| try { | ||
| for ( | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. asdf |
||
| let i = 0; | ||
| i < req.body.allRecurringDates.length && i < req.body.numSlotsToCheckForAvailability; | ||
| i++ | ||
| ) { | ||
| const start = req.body.allRecurringDates[i].start; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. foobar |
||
| const end = req.body.allRecurringDates[i].end; | ||
|
|
||
| await ensureAvailableUsers( | ||
| { ...eventTypeWithUsers, users: [user] }, | ||
| { | ||
| dateFrom: dayjs(start).tz(reqBody.timeZone).format(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test |
||
| dateTo: dayjs(end).tz(reqBody.timeZone).format(), | ||
| timeZone: reqBody.timeZone, | ||
| originalRescheduledBooking, | ||
| }, | ||
| loggerWithEventDetails, | ||
| shouldServeCache | ||
| ); | ||
| } | ||
| // if no error, then lucky user is available for the next slots | ||
| luckyUsers.push(user); | ||
|
Comment on lines
+738
to
+742
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. foo |
||
| } catch { | ||
| notAvailableLuckyUsers.push(user); | ||
| loggerWithEventDetails.info( | ||
| `Round robin host ${user.name} not available for first two slots. Trying to find another host.` | ||
| ); | ||
| } | ||
| // if no error, then lucky user is available for the next slots | ||
| luckyUsers.push(newLuckyUser); | ||
| } catch { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. foobar |
||
| notAvailableLuckyUsers.push(newLuckyUser); | ||
| loggerWithEventDetails.info( | ||
| `Round robin host ${newLuckyUser.name} not available for first two slots. Trying to find another host.` | ||
| ); | ||
| } | ||
| } else { | ||
| luckyUsers.push(newLuckyUser); | ||
| // Add all lucky users | ||
| luckyUsers.push(...usersToProcess); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| } | ||
| // ALL fixed users must be available | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asdf