Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/fix-nightly-2025-2-3-17-27-31.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@azure-tools/typespec-python"
---

add task pool for regeneration
27 changes: 24 additions & 3 deletions packages/typespec-python/scripts/eng/regenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,20 @@ function _getCmdList(spec: string, flags: RegenerateFlags): TspCommand[] {
});
}

async function runTaskPool(tasks: Array<() => Promise<void>>, poolLimit: number): Promise<void> {
let currentIndex = 0;

async function worker() {
while (currentIndex < tasks.length) {
const index = currentIndex++;
await tasks[index]();
}
}

const workers = new Array(Math.min(poolLimit, tasks.length)).fill(null).map(() => worker());
await Promise.all(workers);
}

async function regenerate(flags: RegenerateFlagsInput): Promise<void> {
if (flags.flavor === undefined) {
await regenerate({ ...flags, flavor: "azure" });
Expand All @@ -296,8 +310,14 @@ async function regenerate(flags: RegenerateFlagsInput): Promise<void> {
const cmdList: TspCommand[] = subdirectories.flatMap((subdirectory) =>
_getCmdList(subdirectory, flagsResolved),
);
const PromiseCommands = cmdList.map((tspCommand) => executeCommand(tspCommand));
await Promise.all(PromiseCommands);

// Create tasks as functions for the pool
const tasks: Array<() => Promise<void>> = cmdList.map((tspCommand) => {
return () => executeCommand(tspCommand);
});

// Run tasks with a concurrency limit
await runTaskPool(tasks, 30);
}
}

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

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