+ /**
+ * Creates a new, completely set up dynamic worker node.
+ *
+ * @returns New, completely set up dynamic worker node key.
+ */
+ protected createAndSetupDynamicWorkerNode (): number {
+ const workerNodeKey = this.createAndSetupWorkerNode()
+ this.registerWorkerMessageListener(workerNodeKey, (message) => {
+ const localWorkerNodeKey = this.getWorkerNodeKeyByWorkerId(
+ message.workerId
+ )
+ const workerUsage = this.workerNodes[localWorkerNodeKey].usage
+ // Kill message received from worker
+ if (
+ isKillBehavior(KillBehaviors.HARD, message.kill) ||
+ (isKillBehavior(KillBehaviors.SOFT, message.kill) &&
+ ((this.opts.enableTasksQueue === false &&
+ workerUsage.tasks.executing === 0) ||
+ (this.opts.enableTasksQueue === true &&
+ workerUsage.tasks.executing === 0 &&
+ this.tasksQueueSize(localWorkerNodeKey) === 0)))
+ ) {
+ this.destroyWorkerNode(localWorkerNodeKey).catch((error) => {
+ this.emitter?.emit(PoolEvents.error, error)
+ })
+ }
+ })
+ const workerInfo = this.getWorkerInfo(workerNodeKey) as WorkerInfo
+ this.sendToWorker(workerNodeKey, {
+ checkActive: true,
+ workerId: workerInfo.id as number
+ })
+ workerInfo.dynamic = true
+ if (
+ this.workerChoiceStrategyContext.getStrategyPolicy().dynamicWorkerReady ||
+ this.workerChoiceStrategyContext.getStrategyPolicy().dynamicWorkerUsage
+ ) {
+ workerInfo.ready = true
+ }
+ this.checkAndEmitDynamicWorkerCreationEvents()
+ return workerNodeKey
+ }