2015-10-05 13:13:22 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2015, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link https://www.phptesting.org/
|
|
|
|
*/
|
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
namespace PHPCensor\Command;
|
2015-10-05 13:13:22 +02:00
|
|
|
|
|
|
|
use b8\Config;
|
|
|
|
use Monolog\Logger;
|
2016-07-19 20:28:11 +02:00
|
|
|
use PHPCensor\Logging\OutputLogHandler;
|
|
|
|
use PHPCensor\Worker\BuildWorker;
|
2015-10-05 13:13:22 +02:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Worker Command - Starts the BuildWorker, which pulls jobs from beanstalkd
|
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
|
|
|
* @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')
|
2016-07-19 13:05:02 +02:00
|
|
|
->setDescription('Runs the PHP Censor build worker.')
|
|
|
|
->addOption('debug', null, null, 'Run PHP Censor in Debug Mode');
|
2015-10-05 13:13:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-04-27 15:56:52 +02:00
|
|
|
// Allow PHPCI to run in "debug mode"
|
|
|
|
if ($input->hasOption('debug') && $input->getOption('debug')) {
|
|
|
|
$output->writeln('<comment>Debug mode enabled.</comment>');
|
2016-07-21 17:20:34 +02:00
|
|
|
define('DEBUG_MODE', true);
|
2016-04-27 15:56:52 +02:00
|
|
|
}
|
|
|
|
|
2015-10-05 13:13:22 +02:00
|
|
|
$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();
|
|
|
|
}
|
|
|
|
}
|