From 53331d74f10896dfc07dab2171ab0be7fad04272 Mon Sep 17 00:00:00 2001 From: Ralf Aron Date: Sun, 3 Mar 2024 17:16:58 +0100 Subject: [PATCH] fix: get worker on demand --- projects/aas-server/src/app/aas-provider/parallel.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/projects/aas-server/src/app/aas-provider/parallel.ts b/projects/aas-server/src/app/aas-provider/parallel.ts index bb477a06..87592b20 100644 --- a/projects/aas-server/src/app/aas-provider/parallel.ts +++ b/projects/aas-server/src/app/aas-provider/parallel.ts @@ -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.`); } } @@ -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; }