12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace FD3;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Process\Process;
- use Symfony\Component\Process\Exception\ProcessFailedException;
- class RunParallel extends Command
- {
- protected function configure()
- {
- $this
- ->setName('run:parallel')
- ->setDescription('Run in parallel from the directory of the repo using a ini file.')
- ->setHelp('This command allows you to tag and change the required code on the composer.json file...')
- ->addArgument('ini_file', InputArgument::REQUIRED, 'The ini file from where to get the source code config.')
- ->addArgument('cmd', InputArgument::REQUIRED, 'the command to run in parallel');
- }
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $file = $input->getArgument("ini_file");
- $initial_dir = getcwd();
- $realpath = realpath($file);
- $dirname = dirname($realpath);
- if (!chdir($dirname)) {
- throw new \Exception("Can't change working directory to " . $dirname);
- }
- $content = parse_ini_file($realpath, true);
- $command = $input->getArgument("cmd");
- $p_list = array();
- foreach ($content as $sec => $conf) {
- chdir($dirname . "/" . $sec);
- $output->writeln($sec . "-> " . $command);
- $process = new Process($command);
- //$process->setTimeout(600);
- //$process->setIdleTimeout(6);
- $p_list[$sec] = $process;
- $process->start();
- }
- foreach ($content as $sec => $conf) {
- $process = $p_list[$sec];
- $process->wait();
- $output->writeln("<info>" . $sec . "</info>");
- $output->write($process->getOutput() . "\n");
- }
- chdir($initial_dir);
- }
- }
|