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)
     //        );
 }
Пример #2
0
 public function testForkToWork()
 {
     $me = getmypid();
     $workerRegistry = $this->getMock('Resque\\Component\\Worker\\Registry\\WorkerRegistryInterface');
     $jobInstanceFactory = $this->getMock('Resque\\Component\\Job\\Factory\\JobInstanceFactoryInterface');
     $eventDispatcher = $this->getMock('Resque\\Component\\Core\\Event\\EventDispatcherInterface');
     // @todo move away from mocking.
     $foreman = new Foreman($workerRegistry, $eventDispatcher, new StandardSystem());
     $mockWorker = $this->getMock('Resque\\Component\\Worker\\Worker', array('work'), array($jobInstanceFactory, $eventDispatcher));
     $mockWorker->expects($this->any())->method('work')->will($this->returnValue(null));
     $workers = array(clone $mockWorker, clone $mockWorker, clone $mockWorker);
     $foreman->work($workers, true);
     // Check the workers hold different PIDs
     foreach ($workers as $worker) {
         $this->assertNotEquals(0, $worker->getProcess()->getPid());
         $this->assertNotEquals($me, $worker->getProcess()->getPid());
     }
 }
Пример #3
0
 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.
 }