* @package PHPCI * @subpackage Console */ class WorkerCommand extends Command { /** * @var OutputInterface */ protected $output; /** * @var Logger */ protected $logger; /** * @param \Monolog\Logger $logger * @param string $name */ public function __construct(Logger $logger, $name = null) { parent::__construct($name); $this->logger = $logger; } protected function configure() { $this ->setName('phpci:worker') ->setDescription('Runs the PHP Censor build worker.') ->addOption('debug', null, null, 'Run PHP Censor in Debug Mode'); } protected function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; // For verbose mode we want to output all informational and above // messages to the symphony output interface. if ($input->hasOption('verbose') && $input->getOption('verbose')) { $this->logger->pushHandler( new OutputLogHandler($this->output, Logger::INFO) ); } // Allow PHPCI to run in "debug mode" if ($input->hasOption('debug') && $input->getOption('debug')) { $output->writeln('Debug mode enabled.'); define('PHPCI_DEBUG_MODE', true); } $config = Config::getInstance()->get('phpci.worker', []); if (empty($config['host']) || empty($config['queue'])) { $error = 'The worker is not configured. You must set a host and queue in your config.yml file.'; throw new \Exception($error); } $worker = new BuildWorker($config['host'], $config['queue']); $worker->setLogger($this->logger); $worker->setMaxJobs(Config::getInstance()->get('phpci.worker.max_jobs', -1)); $worker->startWorker(); } }