- if (
- sourceWorkerNode.info.ready &&
- sourceWorkerNode.info.id !== workerId &&
- sourceWorkerNode.usage.tasks.queued > 0
- ) {
- const task = {
- ...(sourceWorkerNode.popTask() as Task<Data>),
- workerId: destinationWorkerNode.info.id as number
- }
- if (
- this.tasksQueueSize(destinationWorkerNodeKey) === 0 &&
- destinationWorkerNode.usage.tasks.executing <
- (this.opts.tasksQueueOptions?.concurrency as number)
- ) {
- this.executeTask(destinationWorkerNodeKey, task)
- } else {
- this.enqueueTask(destinationWorkerNodeKey, task)
- }
- break
+ if (this.shallExecuteTask(destinationWorkerNodeKey)) {
+ this.executeTask(destinationWorkerNodeKey, task)
+ } else {
+ this.enqueueTask(destinationWorkerNodeKey, task)