Skip to content

Commit cd3d8ea

Browse files
authored
fix nightly build (#3049)
1 parent 051ac58 commit cd3d8ea

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@azure-tools/typespec-python"
5+
---
6+
7+
add task pool for regeneration

packages/typespec-python/scripts/eng/regenerate.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,20 @@ function _getCmdList(spec: string, flags: RegenerateFlags): TspCommand[] {
281281
});
282282
}
283283

284+
async function runTaskPool(tasks: Array<() => Promise<void>>, poolLimit: number): Promise<void> {
285+
let currentIndex = 0;
286+
287+
async function worker() {
288+
while (currentIndex < tasks.length) {
289+
const index = currentIndex++;
290+
await tasks[index]();
291+
}
292+
}
293+
294+
const workers = new Array(Math.min(poolLimit, tasks.length)).fill(null).map(() => worker());
295+
await Promise.all(workers);
296+
}
297+
284298
async function regenerate(flags: RegenerateFlagsInput): Promise<void> {
285299
if (flags.flavor === undefined) {
286300
await regenerate({ ...flags, flavor: "azure" });
@@ -296,8 +310,14 @@ async function regenerate(flags: RegenerateFlagsInput): Promise<void> {
296310
const cmdList: TspCommand[] = subdirectories.flatMap((subdirectory) =>
297311
_getCmdList(subdirectory, flagsResolved),
298312
);
299-
const PromiseCommands = cmdList.map((tspCommand) => executeCommand(tspCommand));
300-
await Promise.all(PromiseCommands);
313+
314+
// Create tasks as functions for the pool
315+
const tasks: Array<() => Promise<void>> = cmdList.map((tspCommand) => {
316+
return () => executeCommand(tspCommand);
317+
});
318+
319+
// Run tasks with a concurrency limit
320+
await runTaskPool(tasks, 30);
301321
}
302322
}
303323

@@ -319,6 +339,7 @@ const argv = yargs(hideBin(process.argv))
319339
description: "Specify filename if you only want to generate a subset",
320340
}).argv;
321341

342+
const start = performance.now();
322343
regenerate(argv as RegenerateFlags)
323-
.then(() => console.log("Regeneration successful"))
344+
.then(() => console.log(`Regeneration successful, time taken: ${Math.round((performance.now() - start) / 1000)} s`))
324345
.catch((error) => console.error(`Regeneration failed: ${error.message}`));

0 commit comments

Comments
 (0)