Skip to content

Commit

Permalink
Merge pull request #904 from bcgov/feature/onboarding-scripts
Browse files Browse the repository at this point in the history
feat: make main thread more asynchronous
  • Loading branch information
SoLetsDev authored Jul 19, 2023
2 parents ea72292 + 524db4f commit 98050dd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tools/onboarding/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,21 @@ async function onboardUser(record: UserRecord, instituteType: InstituteTypeCode)

async function main(instituteType: InstituteTypeCode) {
const userRecordStream = createCSVReadStream('./user-records.csv');
let totalUsers = 0;
let usersOnboarded = 0;
let queuedUsers: Promise<boolean>[] = [];

console.log(`::: Begin Onboarding for ${instituteType} Users:::`)
for await (const record of userRecordStream) {
totalUsers++;

if (isUserRecord(record)) {
const onboarded = await onboardUser(record, instituteType);
if (onboarded) usersOnboarded++;
queuedUsers.push(onboardUser(record, instituteType));
} else {
console.log(`Malformed data in CSV row: ${JSON.stringify(record)}`);
}
}

const completedQueue = await Promise.all(queuedUsers);
const totalUsers = completedQueue.length;
const usersOnboarded = completedQueue.filter(u => u === true).length;

console.log(`::: Users Onboarded: ${usersOnboarded}/${totalUsers}:::`);
}

Expand Down

0 comments on commit 98050dd

Please sign in to comment.