예제 #1
0
 public function assertNProcessRunning(QueueInterface &$queue, Processes &$processes = null)
 {
     $parallelProcesses = max(1, min($queue->count(), $this->maxNumberOfParallelProcesses));
     if (null === $processes) {
         $channelsEmpty = range(1, $parallelProcesses);
         $processes = new Processes(array());
         if (false !== $this->beforeCommand && null !== $this->beforeCommand) {
             return $this->createProcessesForTheBeforeCommand($channelsEmpty, $processes);
         }
     } else {
         $channelsEmpty = $processes->getIndexesOfCompletedChannel();
     }
     if (count($channelsEmpty) == 0) {
         usleep(100);
         return true;
     }
     foreach ($channelsEmpty as $currentChannel) {
         if ($queue->isEmpty()) {
             return false;
         }
         $currentProcessNumber = $this->getCurrentProcessCounter();
         $this->incrementForThisChannel($currentChannel);
         $process = $this->processFactory->createAProcess($queue->pop(), $currentChannel, $currentProcessNumber, $this->isFirstForThisChannel($currentChannel));
         $processes->add($currentChannel, $process);
         $processes->start($currentChannel);
     }
     return true;
 }