/** * @param ChannelIsWaitingEvent $event */ public function onChannelIsWaiting(ChannelIsWaitingEvent $event) { $channel = $event->getChannel(); $event->stopPropagation(); $value = null; $isEmpty = true; while ($isEmpty) { try { $value = $this->queue->dequeue(); $isEmpty = false; } catch (\RuntimeException $e) { $isEmpty = true; } if ($isEmpty && $this->queue->isFrozen()) { return; } if ($isEmpty) { usleep(200); } } ++$this->processCounter; $process = $this->processFactory->create($channel, $value, $this->processCounter, $this->template, $this->cwd); $process->start(); $this->eventDispatcher->dispatch(EventsName::PROCESS_STARTED, new ProcessStartedEvent($process)); }
/** * @param QueueInterface $queue * @param string $line */ private function addLineIfNotEmpty(QueueInterface $queue, $line) { if ($line = trim($line)) { $queue->enqueue($line); } }