Skip to content

Commit 7b07d1e

Browse files
split inviteAndJoin into batches (#7298)
1 parent 64c8368 commit 7b07d1e

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

scripts/seed-organization.mts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,41 @@ const password = 'ilikebigturtlesandicannotlie47';
2323

2424
const org = await owner.createOrg();
2525

26-
console.log('Create 100 projects');
26+
const ITEMS_COUNT = 100;
27+
28+
console.log(`Create ${ITEMS_COUNT} projects`);
29+
2730
await PromisePool.withConcurrency(10)
2831
.for(new Array(100).fill(null))
2932
.process(() => org.createProject());
3033

31-
console.log('Create 100 organization members');
32-
await PromisePool.withConcurrency(10)
33-
.for(new Array(100).fill(null))
34-
.process(() => org.inviteAndJoinMember());
34+
console.log(`Create ${ITEMS_COUNT} organization members`);
35+
36+
const RATE_LIMIT_COUNT = 6;
37+
const RATE_LIMIT_WINDOW_MS = 5000;
38+
39+
const members = new Array(ITEMS_COUNT).fill(null);
40+
41+
// Split into batches of 6
42+
const batches = Array.from({ length: Math.ceil(members.length / RATE_LIMIT_COUNT) }, (_, i) =>
43+
members.slice(i * RATE_LIMIT_COUNT, (i + 1) * RATE_LIMIT_COUNT),
44+
);
45+
46+
// Process each batch sequentially, with items in batch processed concurrently
47+
for (const [index, batch] of batches.entries()) {
48+
console.log(`Processing batch ${index + 1}/${batches.length}...`);
49+
50+
await PromisePool.withConcurrency(RATE_LIMIT_COUNT)
51+
.for(batch)
52+
.process(() => org.inviteAndJoinMember());
53+
54+
// Wait between batches (except after the last one)
55+
if (index < batches.length - 1) {
56+
await new Promise(resolve => setTimeout(resolve, RATE_LIMIT_WINDOW_MS));
57+
}
58+
}
59+
60+
console.log(`Completed creating ${ITEMS_COUNT} organization members`);
3561

3662
console.log(`
3763
Seed User Credentials:

0 commit comments

Comments
 (0)