Adding rebuild queue option
This commit is contained in:
parent
9ea6f299c1
commit
4b8d25c0f7
85
PHPCI/Command/RebuildQueueCommand.php
Normal file
85
PHPCI/Command/RebuildQueueCommand.php
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
<?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/
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PHPCI\Command;
|
||||||
|
|
||||||
|
use b8\Config;
|
||||||
|
use b8\Store\Factory;
|
||||||
|
use Monolog\Logger;
|
||||||
|
use PHPCI\BuildFactory;
|
||||||
|
use PHPCI\Helper\Lang;
|
||||||
|
use PHPCI\Logging\OutputLogHandler;
|
||||||
|
use PHPCI\Service\BuildService;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Dan Cryer <dan@block8.co.uk>
|
||||||
|
* @package PHPCI
|
||||||
|
* @subpackage Console
|
||||||
|
*/
|
||||||
|
class RebuildQueueCommand 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:rebuild-queue')
|
||||||
|
->setDescription('Rebuilds the PHPCI worker queue.');
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$store = Factory::getStore('Build');
|
||||||
|
$result = $store->getByStatus(0);
|
||||||
|
|
||||||
|
$this->logger->addInfo(Lang::get('found_n_builds', count($result['items'])));
|
||||||
|
|
||||||
|
$buildService = new BuildService($store);
|
||||||
|
|
||||||
|
while (count($result['items'])) {
|
||||||
|
$build = array_shift($result['items']);
|
||||||
|
$build = BuildFactory::getBuild($build);
|
||||||
|
|
||||||
|
$this->logger->addInfo('Added build #' . $build->getId() . ' to queue.');
|
||||||
|
$buildService->addBuildToQueue($build);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
console
2
console
|
@ -22,6 +22,7 @@ use PHPCI\Command\PollCommand;
|
||||||
use PHPCI\Command\CreateAdminCommand;
|
use PHPCI\Command\CreateAdminCommand;
|
||||||
use PHPCI\Command\CreateBuildCommand;
|
use PHPCI\Command\CreateBuildCommand;
|
||||||
use PHPCI\Command\WorkerCommand;
|
use PHPCI\Command\WorkerCommand;
|
||||||
|
use PHPCI\Command\RebuildQueueCommand;
|
||||||
use PHPCI\Service\BuildService;
|
use PHPCI\Service\BuildService;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use b8\Store\Factory;
|
use b8\Store\Factory;
|
||||||
|
@ -38,5 +39,6 @@ $application->add(new PollCommand($loggerConfig->getFor('PollCommand')));
|
||||||
$application->add(new CreateAdminCommand(Factory::getStore('User')));
|
$application->add(new CreateAdminCommand(Factory::getStore('User')));
|
||||||
$application->add(new CreateBuildCommand(Factory::getStore('Project'), new BuildService(Factory::getStore('Build'))));
|
$application->add(new CreateBuildCommand(Factory::getStore('Project'), new BuildService(Factory::getStore('Build'))));
|
||||||
$application->add(new WorkerCommand($loggerConfig->getFor('WorkerCommand')));
|
$application->add(new WorkerCommand($loggerConfig->getFor('WorkerCommand')));
|
||||||
|
$application->add(new RebuildQueueCommand($loggerConfig->getFor('RebuildQueueCommand')));
|
||||||
|
|
||||||
$application->run();
|
$application->run();
|
||||||
|
|
Loading…
Reference in a new issue