Skip to content

Commit f98b347

Browse files
committed
fix membership provisioning bug
1 parent 5bd03e0 commit f98b347

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/api/functions/general.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export function pollUntilNoError<T>(
2+
fn: () => Promise<T>,
3+
timeout: number,
4+
interval: number = 1000
5+
): Promise<T> {
6+
const start = Date.now();
7+
8+
return new Promise((resolve, reject) => {
9+
const attempt = async () => {
10+
try {
11+
const result = await fn();
12+
return resolve(result);
13+
} catch (err) {
14+
if (Date.now() - start >= timeout) return reject(err);
15+
setTimeout(attempt, interval);
16+
}
17+
};
18+
attempt();
19+
});
20+
}

src/api/functions/membership.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import {
66
} from "@aws-sdk/client-dynamodb";
77
import { marshall } from "@aws-sdk/util-dynamodb";
88
import { genericConfig } from "common/config.js";
9-
import { isUserInGroup, modifyGroup } from "./entraId.js";
9+
import { addToTenant, isUserInGroup, modifyGroup, resolveEmailToOid } from "./entraId.js";
1010
import { EntraGroupError } from "common/errors/index.js";
1111
import { EntraGroupActions } from "common/types/iam.js";
12+
import { pollUntilNoError, sleep } from "./general.js";
1213

1314
export async function checkExternalMembership(
1415
netId: string,
@@ -134,9 +135,14 @@ export async function setPaidMembership({
134135
return { updated: false };
135136
}
136137
}
138+
const email = `${netId}@illinois.edu`;
139+
await addToTenant(entraToken, email);
140+
// Poll every 4 seconds for up to 30 seconds to see if the email was added to the tenant.
141+
// If this still errors, SQS will retry, and if that still errors we'll find it in the DLQ
142+
await pollUntilNoError(() => resolveEmailToOid(entraToken, email), 30000, 4000);
137143
await modifyGroup(
138144
entraToken,
139-
`${netId}@illinois.edu`,
145+
email,
140146
paidMemberGroup,
141147
EntraGroupActions.ADD,
142148
dynamoClient,

0 commit comments

Comments
 (0)