Updates to the daemon / run commands
This commit is contained in:
parent
b91dafab41
commit
4511ba9d60
|
@ -76,6 +76,7 @@ class DaemoniseCommand extends Command
|
||||||
$this->sleep = 0;
|
$this->sleep = 0;
|
||||||
$runner = new RunCommand($this->logger);
|
$runner = new RunCommand($this->logger);
|
||||||
$runner->setMaxBuilds(1);
|
$runner->setMaxBuilds(1);
|
||||||
|
$runner->setIsDaemon(true);
|
||||||
|
|
||||||
$emptyInput = new ArgvInput(array());
|
$emptyInput = new ArgvInput(array());
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,11 @@ class RunCommand extends Command
|
||||||
*/
|
*/
|
||||||
protected $maxBuilds = null;
|
protected $maxBuilds = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $isFromDaemon = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Monolog\Logger $logger
|
* @param \Monolog\Logger $logger
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
@ -90,13 +95,17 @@ class RunCommand extends Command
|
||||||
|
|
||||||
$builds = 0;
|
$builds = 0;
|
||||||
|
|
||||||
foreach ($result['items'] as $build) {
|
while (count($result['items'])) {
|
||||||
|
$build = array_shift($result['items']);
|
||||||
$build = BuildFactory::getBuild($build);
|
$build = BuildFactory::getBuild($build);
|
||||||
|
|
||||||
// Skip build (for now) if there's already a build running in that project:
|
// Skip build (for now) if there's already a build running in that project:
|
||||||
if (in_array($build->getProjectId(), $running)) {
|
if (!$this->isFromDaemon && in_array($build->getProjectId(), $running)) {
|
||||||
$this->logger->addInfo('Skipping Build #'.$build->getId() . ' - Project build already in progress.');
|
$this->logger->addInfo('Skipping Build #'.$build->getId() . ' - Project build already in progress.');
|
||||||
|
$result['items'][] = $build;
|
||||||
|
|
||||||
|
// Re-run build validator:
|
||||||
|
$running = $this->validateRunningBuilds();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +142,11 @@ class RunCommand extends Command
|
||||||
$this->maxBuilds = (int)$numBuilds;
|
$this->maxBuilds = (int)$numBuilds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setIsDaemon($fromDaemon)
|
||||||
|
{
|
||||||
|
$this->isFromDaemon = (bool)$fromDaemon;
|
||||||
|
}
|
||||||
|
|
||||||
protected function validateRunningBuilds()
|
protected function validateRunningBuilds()
|
||||||
{
|
{
|
||||||
/** @var \PHPCI\Store\BuildStore $store */
|
/** @var \PHPCI\Store\BuildStore $store */
|
||||||
|
@ -152,6 +166,7 @@ class RunCommand extends Command
|
||||||
if (($now - $start) > $timeout) {
|
if (($now - $start) > $timeout) {
|
||||||
$this->logger->addInfo('Build #'.$build->getId().' marked as failed due to timeout.');
|
$this->logger->addInfo('Build #'.$build->getId().' marked as failed due to timeout.');
|
||||||
$build->setStatus(Build::STATUS_FAILED);
|
$build->setStatus(Build::STATUS_FAILED);
|
||||||
|
$build->setFinished(new \DateTime());
|
||||||
$store->save($build);
|
$store->save($build);
|
||||||
$this->removeBuildDirectory($build);
|
$this->removeBuildDirectory($build);
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue