Skip to content

Commit

Permalink
fix: get worker on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Mar 3, 2024
1 parent 4e21e60 commit 53331d7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions projects/aas-server/src/app/aas-provider/parallel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ export class Parallel extends EventEmitter {
) {
super();
this.script = path.resolve(this.variable.CONTENT_ROOT, 'aas-scan-worker.js');
if (fs.existsSync(this.script)) {
for (let i = 0; i < this.variable.MAX_WORKERS; i++) {
this.pool.set(new Worker(this.script, { env: SHARE_ENV }), true);
}
} else {
if (!fs.existsSync(this.script)) {
this.logger.error(`${this.script} does not exist.`);
}
}
Expand Down Expand Up @@ -118,6 +114,12 @@ export class Parallel extends EventEmitter {
}
}

if (this.pool.size < this.variable.MAX_WORKERS) {
const worker = new Worker(this.script, { env: SHARE_ENV });
this.pool.set(worker, true);
return worker;
}

return undefined;
}

Expand Down

0 comments on commit 53331d7

Please sign in to comment.