Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15336274
D15371.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D15371.diff
View Options
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 @@
<?php
-final class HarbormasterBuildLog extends HarbormasterDAO
+final class HarbormasterBuildLog
+ extends HarbormasterDAO
implements PhabricatorPolicyInterface {
protected $buildTargetPHID;
@@ -10,7 +11,6 @@
protected $live;
private $buildTarget = self::ATTACHABLE;
- private $start;
const CHUNK_BYTE_LIMIT = 102400;
@@ -20,8 +20,8 @@
const ENCODING_TEXT = 'text';
public function __destruct() {
- if ($this->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);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 9, 6:36 PM (2 d, 7 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7387207
Default Alt Text
D15371.diff (6 KB)
Attached To
Mode
D15371: Slightly simplify the Harbormaster build log API
Attached
Detach File
Event Timeline
Log In to Comment