/** * Find in storage waiting task and free worker of same type * @return array|null * @author Andraz <*****@*****.**> */ public function getWaitingTaskAndFreeWorker() { $tasks = $this->storage->getTasks(); foreach ($tasks as $task) { if (!$task->isWaiting()) { continue; } $workers = $this->storage->getWorkers(); foreach ($workers as $worker) { if ($task->getName() !== $worker->getType()) { continue; } if ($worker->isBusy()) { continue; } return [$task, $worker]; } } return [null, null]; }