feat: worker node readiness aware worker choice strategies
[poolifier.git] / src / pools / abstract-pool.ts
index c200d5317da6ba47c1154cdeb15a9b5ca5c9ee30..812a2087419de6df8d457bd5d875c2d2b5f9f179 100644 (file)
@@ -950,9 +950,6 @@ export abstract class AbstractPool<
       if (this.emitter != null) {
         this.emitter.emit(PoolEvents.error, error)
       }
-      if (this.opts.enableTasksQueue === true) {
-        this.redistributeQueuedTasks(worker)
-      }
       if (this.opts.restartWorkerOnError === true && !this.starting) {
         if (this.getWorkerInfo(this.getWorkerNodeKey(worker)).dynamic) {
           this.createAndSetupDynamicWorker()
@@ -960,6 +957,9 @@ export abstract class AbstractPool<
           this.createAndSetupWorker()
         }
       }
+      if (this.opts.enableTasksQueue === true) {
+        this.redistributeQueuedTasks(worker)
+      }
     })
     worker.on('online', this.opts.onlineHandler ?? EMPTY_FUNCTION)
     worker.on('exit', this.opts.exitHandler ?? EMPTY_FUNCTION)