+ /**
+ * 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
+ ) as number
+ const workerUsage = this.workerNodes[localWorkerNodeKey].usage
+ if (
+ isKillBehavior(KillBehaviors.HARD, message.kill) ||
+ (message.kill != null &&
+ ((this.opts.enableTasksQueue === false &&
+ workerUsage.tasks.executing === 0) ||
+ (this.opts.enableTasksQueue === true &&
+ workerUsage.tasks.executing === 0 &&
+ this.tasksQueueSize(localWorkerNodeKey) === 0)))
+ ) {
+ // Kill message received from the worker: no new tasks are submitted to that worker for a while ( > maxInactiveTime)
+ const destroyWorkerNodeBounded = this.destroyWorkerNode.bind(this)
+ if (isAsyncFunction(destroyWorkerNodeBounded)) {
+ (
+ destroyWorkerNodeBounded as (workerNodeKey: number) => Promise<void>
+ )(localWorkerNodeKey).catch(EMPTY_FUNCTION)
+ } else {
+ (destroyWorkerNodeBounded as (workerNodeKey: number) => void)(
+ localWorkerNodeKey
+ )
+ }
+ }
+ })
+ const workerInfo = this.getWorkerInfo(workerNodeKey)
+ workerInfo.dynamic = true
+ if (this.workerChoiceStrategyContext.getStrategyPolicy().useDynamicWorker) {
+ workerInfo.ready = true
+ }
+ this.sendToWorker(workerNodeKey, {
+ checkActive: true,
+ workerId: workerInfo.id as number
+ })
+ return workerNodeKey
+ }