@@ -271,10 +271,6 @@ export class WorkerManager implements IWorkerManager {
271271 await group . addMembers ( extraMembers ) ;
272272 }
273273
274- for ( const member of memberList ) {
275- await group . addAdmin ( member ) ;
276- }
277-
278274 return group as Group ;
279275 }
280276
@@ -516,7 +512,7 @@ export async function getWorkers(
516512 ( v ) => v . nodeBindings ,
517513 ) ;
518514 }
519- let successfulResults : Worker [ ] = [ ] ;
515+ let workerPromises : Promise < Worker > [ ] = [ ] ;
520516 let descriptors : string [ ] = [ ] ;
521517
522518 // Handle different input types
@@ -528,75 +524,68 @@ export async function getWorkers(
528524 : getFixedNames ( workers )
529525 : workers ;
530526 descriptors = names ;
531- for ( const descriptor of descriptors ) {
532- successfulResults . push (
533- await manager . createWorker (
534- descriptor ,
535- sdkVersions [ Math . floor ( Math . random ( ) * sdkVersions . length ) ] ,
536- ) ,
537- ) ;
538- }
527+ workerPromises = descriptors . map ( ( descriptor ) =>
528+ manager . createWorker (
529+ descriptor ,
530+ sdkVersions [ Math . floor ( Math . random ( ) * sdkVersions . length ) ] ,
531+ ) ,
532+ ) ;
539533 } else {
540534 // Record input - apply versioning if requested
541535 let entries = Object . entries ( workers ) ;
542536
543537 descriptors = entries . map ( ( [ descriptor ] ) => descriptor ) ;
544- for ( const descriptor of descriptors ) {
545- successfulResults . push (
546- await manager . createWorker (
547- descriptor ,
548- sdkVersions [ Math . floor ( Math . random ( ) * sdkVersions . length ) ] ,
549- ) ,
550- ) ;
551- }
538+ workerPromises = entries . map ( ( [ descriptor , apiUrl ] ) =>
539+ manager . createWorker ( descriptor , sdkVersions [ 0 ] , apiUrl ) ,
540+ ) ;
541+ }
542+
543+ // Only use progress bar if there are more than 50 workers
544+ const useProgressBar = workerPromises . length > 50 ;
545+ let progressBar : ProgressBar | undefined ;
546+
547+ if ( useProgressBar ) {
548+ progressBar = new ProgressBar (
549+ workerPromises . length ,
550+ `Initializing ${ workerPromises . length } workers...` ,
551+ ) ;
552+ // Show initial progress immediately
553+ progressBar . update ( 0 ) ;
552554 }
553555
554- // // Only use progress bar if there are more than 50 workers
555- // const useProgressBar = workerPromises.length > 50;
556- // let progressBar: ProgressBar | undefined;
557-
558- // if (useProgressBar) {
559- // progressBar = new ProgressBar(
560- // workerPromises.length,
561- // `Initializing ${workerPromises.length} workers...`,
562- // );
563- // // Show initial progress immediately
564- // progressBar.update(0);
565- // }
566-
567- // // Track all workers in parallel and update progress as each completes
568- // let completedCount = 0;
569- // const results = await Promise.allSettled(
570- // workerPromises.map(async (workerPromise) => {
571- // try {
572- // const worker = await workerPromise;
573- // completedCount++;
574- // if (useProgressBar && progressBar) {
575- // progressBar.update(completedCount);
576- // }
577- // return worker;
578- // } catch (error) {
579- // completedCount++;
580- // if (useProgressBar && progressBar) {
581- // progressBar.update(completedCount);
582- // }
583- // throw error;
584- // }
585- // }),
586- // );
587-
588- // // Check for any failures
589- // const failedResults = results.filter(
590- // (result) => result.status === "rejected",
591- // );
592- // if (failedResults.length > 0) {
593- // throw failedResults[0].reason;
594- // }
595-
596- // // Extract successful results
597- // const successfulResults = results.map(
598- // (result) => (result as PromiseFulfilledResult<Worker>).value,
599- // );
556+ // Track all workers in parallel and update progress as each completes
557+ let completedCount = 0 ;
558+ const results = await Promise . allSettled (
559+ workerPromises . map ( async ( workerPromise ) => {
560+ try {
561+ const worker = await workerPromise ;
562+ completedCount ++ ;
563+ if ( useProgressBar && progressBar ) {
564+ progressBar . update ( completedCount ) ;
565+ }
566+ return worker ;
567+ } catch ( error ) {
568+ completedCount ++ ;
569+ if ( useProgressBar && progressBar ) {
570+ progressBar . update ( completedCount ) ;
571+ }
572+ throw error ;
573+ }
574+ } ) ,
575+ ) ;
576+
577+ // Check for any failures
578+ const failedResults = results . filter (
579+ ( result ) => result . status === "rejected" ,
580+ ) ;
581+ if ( failedResults . length > 0 ) {
582+ throw failedResults [ 0 ] . reason ;
583+ }
584+
585+ // Extract successful results
586+ const successfulResults = results . map (
587+ ( result ) => ( result as PromiseFulfilledResult < Worker > ) . value ,
588+ ) ;
600589
601590 // Add all successful workers to the manager
602591 for ( const worker of successfulResults ) {
@@ -625,11 +614,12 @@ function getNextFolderName(): string {
625614 const dataPath = path . resolve ( process . cwd ( ) , ".data" ) ;
626615 let folder = "a" ;
627616 if ( fs . existsSync ( dataPath ) ) {
628- const chars = "abcdefghijklmnopqrstuvwxyz0123456789" ;
629- folder = Array . from (
630- { length : 32 } ,
631- ( ) => chars [ Math . floor ( Math . random ( ) * chars . length ) ] ,
632- ) . join ( "" ) ;
617+ const existingFolders = fs
618+ . readdirSync ( dataPath )
619+ . filter ( ( f ) => / ^ [ a - z ] $ / . test ( f ) ) ;
620+ folder = String . fromCharCode (
621+ "a" . charCodeAt ( 0 ) + ( existingFolders . length % 26 ) ,
622+ ) ;
633623 }
634624 return folder ;
635625}
0 commit comments