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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: internal
packages:
- "@typespec/http-client-python"
---

add task pool for regeneration
31 changes: 28 additions & 3 deletions packages/http-client-python/eng/scripts/ci/regenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,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({ flavor: "azure", ...flags });
Expand All @@ -331,11 +345,22 @@ 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);
}
}

const start = performance.now();
regenerate(argv.values)
.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