コード例 #1
0
ファイル: Manager.php プロジェクト: andrazk/queue_manager
 /**
  * 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];
 }