split inviteAndJoin into batches (#7298)

This commit is contained in:
Jonathan Brennan 2025-11-20 19:53:45 -06:00 committed by GitHub
parent 64c8368c4b
commit 7b07d1e374
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -23,15 +23,41 @@ const password = 'ilikebigturtlesandicannotlie47';
const org = await owner.createOrg();
console.log('Create 100 projects');
const ITEMS_COUNT = 100;
console.log(`Create ${ITEMS_COUNT} projects`);
await PromisePool.withConcurrency(10)
.for(new Array(100).fill(null))
.process(() => org.createProject());
console.log('Create 100 organization members');
await PromisePool.withConcurrency(10)
.for(new Array(100).fill(null))
.process(() => org.inviteAndJoinMember());
console.log(`Create ${ITEMS_COUNT} organization members`);
const RATE_LIMIT_COUNT = 6;
const RATE_LIMIT_WINDOW_MS = 5000;
const members = new Array(ITEMS_COUNT).fill(null);
// Split into batches of 6
const batches = Array.from({ length: Math.ceil(members.length / RATE_LIMIT_COUNT) }, (_, i) =>
members.slice(i * RATE_LIMIT_COUNT, (i + 1) * RATE_LIMIT_COUNT),
);
// Process each batch sequentially, with items in batch processed concurrently
for (const [index, batch] of batches.entries()) {
console.log(`Processing batch ${index + 1}/${batches.length}...`);
await PromisePool.withConcurrency(RATE_LIMIT_COUNT)
.for(batch)
.process(() => org.inviteAndJoinMember());
// Wait between batches (except after the last one)
if (index < batches.length - 1) {
await new Promise(resolve => setTimeout(resolve, RATE_LIMIT_WINDOW_MS));
}
}
console.log(`Completed creating ${ITEMS_COUNT} organization members`);
console.log(`
Seed User Credentials: