diff --git a/src/applications/harbormaster/step/HarbormasterWaitForPreviousBuildStepImplementation.php b/src/applications/harbormaster/step/HarbormasterWaitForPreviousBuildStepImplementation.php --- a/src/applications/harbormaster/step/HarbormasterWaitForPreviousBuildStepImplementation.php +++ b/src/applications/harbormaster/step/HarbormasterWaitForPreviousBuildStepImplementation.php @@ -31,24 +31,7 @@ // Block until all previous builds of the same build plan have // finished. $plan = $build->getBuildPlan(); - - $existing_logs = id(new HarbormasterBuildLogQuery()) - ->setViewer(PhabricatorUser::getOmnipotentUser()) - ->withBuildTargetPHIDs(array($build_target->getPHID())) - ->execute(); - - if ($existing_logs) { - $log = head($existing_logs); - } else { - $log = $build->createLog($build_target, 'waiting', 'blockers'); - } - $blockers = $this->getBlockers($object, $plan, $build); - if ($blockers) { - $log->start(); - $log->append(pht("Blocked by: %s\n", implode(',', $blockers))); - $log->finalize(); - } if ($blockers) { throw new PhabricatorWorkerYieldException(15); diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuild.php b/src/applications/harbormaster/storage/build/HarbormasterBuild.php --- a/src/applications/harbormaster/storage/build/HarbormasterBuild.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuild.php @@ -234,23 +234,6 @@ return ($this->getPlanAutoKey() !== null); } - public function createLog( - HarbormasterBuildTarget $build_target, - $log_source, - $log_type) { - - $log_source = id(new PhutilUTF8StringTruncator()) - ->setMaximumBytes(250) - ->truncateString($log_source); - - $log = HarbormasterBuildLog::initializeNewBuildLog($build_target) - ->setLogSource($log_source) - ->setLogType($log_type) - ->save(); - - return $log; - } - public function retrieveVariablesFromBuild() { $results = array( 'buildable.diff' => null, diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php b/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php --- a/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php @@ -1,6 +1,7 @@ start) { - $this->finalize($this->start); + if ($this->getLive()) { + $this->closeBuildLog(); } } @@ -34,6 +34,35 @@ ->setLive(0); } + public function openBuildLog() { + if ($this->getLive()) { + throw new Exception(pht('This build log is already open!')); + } + + return $this + ->setLive(1) + ->save(); + } + + public function closeBuildLog() { + if (!$this->getLive()) { + throw new Exception(pht('This build log is not open!')); + } + + // TODO: Encode the log contents in a gzipped format. + + $this->reload(); + + $start = $this->getDateCreated(); + $now = PhabricatorTime::getNow(); + + return $this + ->setDuration($now - $start) + ->setLive(0) + ->save(); + } + + protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, @@ -73,26 +102,13 @@ return pht('Build Log'); } - public function start() { - if ($this->getLive()) { - throw new Exception( - pht('Live logging has already started for this log.')); - } - - $this->setLive(1); - $this->save(); - - $this->start = PhabricatorTime::getNow(); - - return time(); - } - public function append($content) { if (!$this->getLive()) { - throw new Exception( - pht('Start logging before appending data to the log.')); + throw new PhutilInvalidStateException('openBuildLog'); } - if (strlen($content) === 0) { + + $content = (string)$content; + if (!strlen($content)) { return; } @@ -152,21 +168,6 @@ } } - public function finalize($start = 0) { - if (!$this->getLive()) { - // TODO: Clean up this API. - return; - } - - // TODO: Encode the log contents in a gzipped format. - $this->reload(); - if ($start > 0) { - $this->setDuration(time() - $start); - } - $this->setLive(0); - $this->save(); - } - public function getLogText() { // TODO: This won't cope very well if we're pulling like a 700MB // log file out of the DB. We should probably implement some sort diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php b/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php --- a/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php @@ -256,9 +256,8 @@ $log = HarbormasterBuildLog::initializeNewBuildLog($this) ->setLogSource($log_source) - ->setLogType($log_type); - - $log->start(); + ->setLogType($log_type) + ->openBuildLog(); return $log; } diff --git a/src/applications/harbormaster/worker/HarbormasterTargetWorker.php b/src/applications/harbormaster/worker/HarbormasterTargetWorker.php --- a/src/applications/harbormaster/worker/HarbormasterTargetWorker.php +++ b/src/applications/harbormaster/worker/HarbormasterTargetWorker.php @@ -90,13 +90,10 @@ $target->setDateCompleted(PhabricatorTime::getNow()); $target->save(); } catch (Exception $ex) { - phlog($ex); - try { - $log = $build->createLog($target, 'core', 'exception'); - $start = $log->start(); - $log->append((string)$ex); - $log->finalize($start); + $log = $target->newLog('core', 'exception') + ->append($ex) + ->closeBuildLog(); } catch (Exception $log_ex) { phlog($log_ex); }