/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $client = $this->getContainer()->get('gearman'); $workers = $client->getWorkers(); $results = ['programs' => []]; $phpPath = $this->getContainer()->getParameter('dream_commerce_gearman.config')['php_path']; $workersConfig = $this->getContainer()->getParameter('dream_commerce_gearman.config')['workers']; $prefix = $this->getContainer()->getParameter('dream_commerce_gearman.config')['name_prefix']; foreach ($workers as $w) { foreach ($w['jobs'] as $x) { $directory = realpath($this->getContainer()->getParameter('kernel.root_dir') . '/../'); $command = sprintf('%s bin/console gearman:job:execute %s -n --env=prod', $phpPath, $x['realCallableNameNoPrefix']); // worker not configured if (!isset($workersConfig[$x['realCallableNameNoPrefix']])) { continue; } $numProcs = $workersConfig[$x['realCallableNameNoPrefix']] ?: 3; if (!$numProcs) { continue; } $name = !$prefix ? $x['realCallableNameNoPrefix'] : sprintf('%s_%s', $prefix, $x['realCallableNameNoPrefix']); $results['programs'][] = ['name' => $name, 'directory' => $directory, 'command' => $command, 'process_name' => '%(program_name)s_%(process_num)02d', 'autostart' => 'true', 'autorestart' => 'true', 'numprocs' => $numProcs]; } } if ($results['programs']) { $cfg = new Configuration(); $cfg->registerProcessor(new CommandConfigurationProcessor()); $loader = new ArrayLoader(); $loader->setSource($results); $loader->setConfiguration($cfg); $gen = $loader->load(); $output->writeln($gen->generate()); } }