From 4511ba9d609ec89fe940ff1177b56c943289dab7 Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Wed, 3 Dec 2014 13:28:40 +0000 Subject: [PATCH] Updates to the daemon / run commands --- PHPCI/Command/DaemoniseCommand.php | 1 + PHPCI/Command/RunCommand.php | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/PHPCI/Command/DaemoniseCommand.php b/PHPCI/Command/DaemoniseCommand.php index d2f1f236..915890bd 100644 --- a/PHPCI/Command/DaemoniseCommand.php +++ b/PHPCI/Command/DaemoniseCommand.php @@ -76,6 +76,7 @@ class DaemoniseCommand extends Command $this->sleep = 0; $runner = new RunCommand($this->logger); $runner->setMaxBuilds(1); + $runner->setIsDaemon(true); $emptyInput = new ArgvInput(array()); diff --git a/PHPCI/Command/RunCommand.php b/PHPCI/Command/RunCommand.php index f1c02360..b384100d 100644 --- a/PHPCI/Command/RunCommand.php +++ b/PHPCI/Command/RunCommand.php @@ -48,6 +48,11 @@ class RunCommand extends Command */ protected $maxBuilds = null; + /** + * @var bool + */ + protected $isFromDaemon = false; + /** * @param \Monolog\Logger $logger * @param string $name @@ -90,13 +95,17 @@ class RunCommand extends Command $builds = 0; - foreach ($result['items'] as $build) { - + while (count($result['items'])) { + $build = array_shift($result['items']); $build = BuildFactory::getBuild($build); // 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.'); + $result['items'][] = $build; + + // Re-run build validator: + $running = $this->validateRunningBuilds(); continue; } @@ -133,6 +142,11 @@ class RunCommand extends Command $this->maxBuilds = (int)$numBuilds; } + public function setIsDaemon($fromDaemon) + { + $this->isFromDaemon = (bool)$fromDaemon; + } + protected function validateRunningBuilds() { /** @var \PHPCI\Store\BuildStore $store */ @@ -152,6 +166,7 @@ class RunCommand extends Command if (($now - $start) > $timeout) { $this->logger->addInfo('Build #'.$build->getId().' marked as failed due to timeout.'); $build->setStatus(Build::STATUS_FAILED); + $build->setFinished(new \DateTime()); $store->save($build); $this->removeBuildDirectory($build); continue;