protected function execute(InputInterface $input, OutputInterface $output) { $output = new SymfonyStyle($input, $output); $workerCount = $input->getOption('count'); $queues = $this->createQueues($input->getArgument('queues')); $output->write($queues); // This method of worker setup requires an array of queues if (!is_array($queues)) { throw new \Exception("Queues not initialized correctly"); } $workers = array(); for ($i = 0; $i < $workerCount; ++$i) { $worker = $this->workerFactory->createWorker(); $workerProcess = $this->workerFactory->createWorkerProcess($worker); foreach ($queues as $queue) { $worker->addQueue($queue); } $workers[] = $workerProcess; } $this->foreman->pruneDeadWorkers(); $this->foreman->work($workers, $input->getOption('wait')); echo sprintf('%d workers attached to the %s queues successfully started.', count($workers), implode($queues, ',')); // echo sprintf( // 'Workers (%s)', // implode(', ', $workers) // ); }
public function work() { $this->foreman->pruneDeadWorkers(); $this->foreman->work($this->workers); echo sprintf('%d workers attached to the %s queues successfully started.' . PHP_EOL, count($this->workers), $this->queueDescription()); echo sprintf('Workers (%s)' . PHP_EOL, implode(', ', $this->workers)); // $this->foreman->wait($this->workers); @todo this is not intended, work out why this is needed. }