1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-27 07:50:57 +01:00

Slightly simplify the Harbormaster build log API

Summary:
Ref T5822. This prepares for inline compression and garbage collection of build logs.

This reduces the API surface area and removes a log from the "wait" step that would just log a message every 15 seconds. (If this is actually useful, I think we find a better way to communicate it.)

Test Plan:
Ran a build, saw a log:

{F1136691}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T5822

Differential Revision: https://secure.phabricator.com/D15371
This commit is contained in:
epriestley 2016-03-01 06:39:26 -08:00
parent 58aac5de0e
commit cf0957451e
5 changed files with 42 additions and 79 deletions

View file

@ -31,24 +31,7 @@ final class HarbormasterWaitForPreviousBuildStepImplementation
// Block until all previous builds of the same build plan have // Block until all previous builds of the same build plan have
// finished. // finished.
$plan = $build->getBuildPlan(); $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); $blockers = $this->getBlockers($object, $plan, $build);
if ($blockers) {
$log->start();
$log->append(pht("Blocked by: %s\n", implode(',', $blockers)));
$log->finalize();
}
if ($blockers) { if ($blockers) {
throw new PhabricatorWorkerYieldException(15); throw new PhabricatorWorkerYieldException(15);

View file

@ -234,23 +234,6 @@ final class HarbormasterBuild extends HarbormasterDAO
return ($this->getPlanAutoKey() !== null); 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() { public function retrieveVariablesFromBuild() {
$results = array( $results = array(
'buildable.diff' => null, 'buildable.diff' => null,

View file

@ -1,6 +1,7 @@
<?php <?php
final class HarbormasterBuildLog extends HarbormasterDAO final class HarbormasterBuildLog
extends HarbormasterDAO
implements PhabricatorPolicyInterface { implements PhabricatorPolicyInterface {
protected $buildTargetPHID; protected $buildTargetPHID;
@ -10,7 +11,6 @@ final class HarbormasterBuildLog extends HarbormasterDAO
protected $live; protected $live;
private $buildTarget = self::ATTACHABLE; private $buildTarget = self::ATTACHABLE;
private $start;
const CHUNK_BYTE_LIMIT = 102400; const CHUNK_BYTE_LIMIT = 102400;
@ -20,8 +20,8 @@ final class HarbormasterBuildLog extends HarbormasterDAO
const ENCODING_TEXT = 'text'; const ENCODING_TEXT = 'text';
public function __destruct() { public function __destruct() {
if ($this->start) { if ($this->getLive()) {
$this->finalize($this->start); $this->closeBuildLog();
} }
} }
@ -34,6 +34,35 @@ final class HarbormasterBuildLog extends HarbormasterDAO
->setLive(0); ->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() { protected function getConfiguration() {
return array( return array(
self::CONFIG_AUX_PHID => true, self::CONFIG_AUX_PHID => true,
@ -73,26 +102,13 @@ final class HarbormasterBuildLog extends HarbormasterDAO
return pht('Build Log'); 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) { public function append($content) {
if (!$this->getLive()) { if (!$this->getLive()) {
throw new Exception( throw new PhutilInvalidStateException('openBuildLog');
pht('Start logging before appending data to the log.'));
} }
if (strlen($content) === 0) {
$content = (string)$content;
if (!strlen($content)) {
return; return;
} }
@ -152,21 +168,6 @@ final class HarbormasterBuildLog extends HarbormasterDAO
} }
} }
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() { public function getLogText() {
// TODO: This won't cope very well if we're pulling like a 700MB // 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 // log file out of the DB. We should probably implement some sort

View file

@ -256,9 +256,8 @@ final class HarbormasterBuildTarget extends HarbormasterDAO
$log = HarbormasterBuildLog::initializeNewBuildLog($this) $log = HarbormasterBuildLog::initializeNewBuildLog($this)
->setLogSource($log_source) ->setLogSource($log_source)
->setLogType($log_type); ->setLogType($log_type)
->openBuildLog();
$log->start();
return $log; return $log;
} }

View file

@ -90,13 +90,10 @@ final class HarbormasterTargetWorker extends HarbormasterWorker {
$target->setDateCompleted(PhabricatorTime::getNow()); $target->setDateCompleted(PhabricatorTime::getNow());
$target->save(); $target->save();
} catch (Exception $ex) { } catch (Exception $ex) {
phlog($ex);
try { try {
$log = $build->createLog($target, 'core', 'exception'); $log = $target->newLog('core', 'exception')
$start = $log->start(); ->append($ex)
$log->append((string)$ex); ->closeBuildLog();
$log->finalize($start);
} catch (Exception $log_ex) { } catch (Exception $log_ex) {
phlog($log_ex); phlog($log_ex);
} }