Merge dependabot/npm_and_yarn/examples/typescript/http-server-pool/fastify-cluster...
[poolifier.git] / src / pools / abstract-pool.ts
index 4abbd615efe13869feaff7b9e1b19ee584b17990..6081902720554c2bcdb809d37f04d5f93ed89da7 100644 (file)
@@ -1269,8 +1269,15 @@ export abstract class AbstractPool<
         } else {
           this.enqueueTask(destinationWorkerNodeKey, task)
         }
-        ++destinationWorkerNode.usage.tasks.stolen
-        if (this.shallUpdateTaskFunctionWorkerUsage(destinationWorkerNodeKey)) {
+        if (destinationWorkerNode?.usage != null) {
+          ++destinationWorkerNode.usage.tasks.stolen
+        }
+        if (
+          this.shallUpdateTaskFunctionWorkerUsage(destinationWorkerNodeKey) &&
+          destinationWorkerNode.getTaskFunctionWorkerUsage(
+            task.name as string
+          ) != null
+        ) {
           const taskFunctionWorkerUsage =
             destinationWorkerNode.getTaskFunctionWorkerUsage(
               task.name as string
@@ -1312,8 +1319,13 @@ export abstract class AbstractPool<
         } else {
           this.enqueueTask(workerNodeKey, task)
         }
-        ++workerNode.usage.tasks.stolen
-        if (this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey)) {
+        if (workerNode?.usage != null) {
+          ++workerNode.usage.tasks.stolen
+        }
+        if (
+          this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
+          workerNode.getTaskFunctionWorkerUsage(task.name as string) != null
+        ) {
           const taskFunctionWorkerUsage = workerNode.getTaskFunctionWorkerUsage(
             task.name as string
           ) as WorkerUsage