Пример #1
0
 /**
  * Create a Manager instance using config
  *
  * @param  $path
  * @return static
  * @throws \Exception
  */
 public static function factory($path)
 {
     $pools = array();
     try {
         if (file_exists($path)) {
             $config = Config::load($path);
             foreach ($config->get('workers', array()) as $worker) {
                 $count = array_key_exists('count', $worker) ? $worker['count'] : null;
                 $options = array_key_exists('options', $worker) ? $worker['options'] : array();
                 $pool = new Pool($count);
                 $pool->add(new Worker(new Process(new Command($worker['path'], $options))));
                 $pools[] = $pool;
             }
         }
     } catch (\Exception $e) {
         throw $e;
     }
     $instance = new static($pools);
     return $instance;
 }
Пример #2
0
 public function testPoolSpawnTooManyWorkers()
 {
     $pool = new Pool(5);
     $pool->setOutput(new NullOutput());
     $command = new Command('echo foo');
     $process = new Process($command);
     $worker = new Worker($process);
     // Nullify the output
     $process->setOutput(new NullOutput());
     $worker->setOutput(new NullOutput());
     $pool->setWorkerInstance($worker);
     $this->assertEquals(0, count($pool->getWorkers()));
     $this->setExpectedException('\\Exception');
     for ($i = 0; $i < 6; $i++) {
         $pool->spawn();
         $this->assertEquals($i + 1, count($pool->getWorkers()));
     }
 }