X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fcluster-worker.ts;h=0fd9095625fa7ab6bf4bd9203cbf9b4e2ef03348;hb=5aa31a743fde300612ae89a242b809ae7db083ed;hp=08eb4e89c81e18e33d02ebae675395e3fe8b33d6;hpb=29d8b961b1907797d251871a97092973d342c63c;p=poolifier.git diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index 08eb4e89..0fd90956 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -33,7 +33,7 @@ export class ClusterWorker< opts: WorkerOptions = {} ) { super( - 'worker-cluster-pool:poolifier', + 'poolifier:cluster-worker', cluster.isPrimary, cluster.worker as Worker, taskFunctions, @@ -43,9 +43,19 @@ export class ClusterWorker< /** @inheritDoc */ protected handleReadyMessage (message: MessageValue): void { - if (message.workerId === this.id && message.ready != null) { - this.getMainWorker()?.on('message', this.messageListener.bind(this)) - this.sendToMainWorker({ ready: true, workerId: this.id }) + if (message.workerId === this.id && message.ready === false) { + try { + this.getMainWorker().on('message', this.messageListener.bind(this)) + this.sendToMainWorker({ + ready: true, + taskFunctionNames: this.listTaskFunctionNames() + }) + } catch { + this.sendToMainWorker({ + ready: false, + taskFunctionNames: this.listTaskFunctionNames() + }) + } } } @@ -56,6 +66,6 @@ export class ClusterWorker< /** @inheritDoc */ protected sendToMainWorker (message: MessageValue): void { - this.getMainWorker().send(message) + this.getMainWorker().send({ ...message, workerId: this.id }) } }