/** * 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; }
public function testPoolImmutableWorkerAdd() { $pool = new Pool(2); $pool->setOutput(new NullOutput()); $command1 = new Command('echo foo'); $process1 = new Process($command1); $worker1 = new Worker($process1); // Nullify the output $process1->setOutput(new NullOutput()); $worker1->setOutput(new NullOutput()); $command2 = new Command('echo bar'); $process2 = new Process($command2); $worker2 = new Worker($process2); // Nullify the output $process2->setOutput(new NullOutput()); $worker2->setOutput(new NullOutput()); $this->setExpectedException('\\Exception'); // Set / Add worker1 $pool->add($worker1); // Invalid worker instance $pool->add($worker2); }