@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+42 -79
-17
src/applications/harbormaster/step/HarbormasterWaitForPreviousBuildStepImplementation.php
··· 31 31 // Block until all previous builds of the same build plan have 32 32 // finished. 33 33 $plan = $build->getBuildPlan(); 34 - 35 - $existing_logs = id(new HarbormasterBuildLogQuery()) 36 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 37 - ->withBuildTargetPHIDs(array($build_target->getPHID())) 38 - ->execute(); 39 - 40 - if ($existing_logs) { 41 - $log = head($existing_logs); 42 - } else { 43 - $log = $build->createLog($build_target, 'waiting', 'blockers'); 44 - } 45 - 46 34 $blockers = $this->getBlockers($object, $plan, $build); 47 - if ($blockers) { 48 - $log->start(); 49 - $log->append(pht("Blocked by: %s\n", implode(',', $blockers))); 50 - $log->finalize(); 51 - } 52 35 53 36 if ($blockers) { 54 37 throw new PhabricatorWorkerYieldException(15);
-17
src/applications/harbormaster/storage/build/HarbormasterBuild.php
··· 234 234 return ($this->getPlanAutoKey() !== null); 235 235 } 236 236 237 - public function createLog( 238 - HarbormasterBuildTarget $build_target, 239 - $log_source, 240 - $log_type) { 241 - 242 - $log_source = id(new PhutilUTF8StringTruncator()) 243 - ->setMaximumBytes(250) 244 - ->truncateString($log_source); 245 - 246 - $log = HarbormasterBuildLog::initializeNewBuildLog($build_target) 247 - ->setLogSource($log_source) 248 - ->setLogType($log_type) 249 - ->save(); 250 - 251 - return $log; 252 - } 253 - 254 237 public function retrieveVariablesFromBuild() { 255 238 $results = array( 256 239 'buildable.diff' => null,
+37 -36
src/applications/harbormaster/storage/build/HarbormasterBuildLog.php
··· 1 1 <?php 2 2 3 - final class HarbormasterBuildLog extends HarbormasterDAO 3 + final class HarbormasterBuildLog 4 + extends HarbormasterDAO 4 5 implements PhabricatorPolicyInterface { 5 6 6 7 protected $buildTargetPHID; ··· 10 11 protected $live; 11 12 12 13 private $buildTarget = self::ATTACHABLE; 13 - private $start; 14 14 15 15 const CHUNK_BYTE_LIMIT = 102400; 16 16 ··· 20 20 const ENCODING_TEXT = 'text'; 21 21 22 22 public function __destruct() { 23 - if ($this->start) { 24 - $this->finalize($this->start); 23 + if ($this->getLive()) { 24 + $this->closeBuildLog(); 25 25 } 26 26 } 27 27 ··· 33 33 ->setDuration(null) 34 34 ->setLive(0); 35 35 } 36 + 37 + public function openBuildLog() { 38 + if ($this->getLive()) { 39 + throw new Exception(pht('This build log is already open!')); 40 + } 41 + 42 + return $this 43 + ->setLive(1) 44 + ->save(); 45 + } 46 + 47 + public function closeBuildLog() { 48 + if (!$this->getLive()) { 49 + throw new Exception(pht('This build log is not open!')); 50 + } 51 + 52 + // TODO: Encode the log contents in a gzipped format. 53 + 54 + $this->reload(); 55 + 56 + $start = $this->getDateCreated(); 57 + $now = PhabricatorTime::getNow(); 58 + 59 + return $this 60 + ->setDuration($now - $start) 61 + ->setLive(0) 62 + ->save(); 63 + } 64 + 36 65 37 66 protected function getConfiguration() { 38 67 return array( ··· 73 102 return pht('Build Log'); 74 103 } 75 104 76 - public function start() { 77 - if ($this->getLive()) { 78 - throw new Exception( 79 - pht('Live logging has already started for this log.')); 80 - } 81 - 82 - $this->setLive(1); 83 - $this->save(); 84 - 85 - $this->start = PhabricatorTime::getNow(); 86 - 87 - return time(); 88 - } 89 - 90 105 public function append($content) { 91 106 if (!$this->getLive()) { 92 - throw new Exception( 93 - pht('Start logging before appending data to the log.')); 107 + throw new PhutilInvalidStateException('openBuildLog'); 94 108 } 95 - if (strlen($content) === 0) { 109 + 110 + $content = (string)$content; 111 + if (!strlen($content)) { 96 112 return; 97 113 } 98 114 ··· 150 166 $content, 151 167 $result[0]['id']); 152 168 } 153 - } 154 - 155 - public function finalize($start = 0) { 156 - if (!$this->getLive()) { 157 - // TODO: Clean up this API. 158 - return; 159 - } 160 - 161 - // TODO: Encode the log contents in a gzipped format. 162 - $this->reload(); 163 - if ($start > 0) { 164 - $this->setDuration(time() - $start); 165 - } 166 - $this->setLive(0); 167 - $this->save(); 168 169 } 169 170 170 171 public function getLogText() {
+2 -3
src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php
··· 256 256 257 257 $log = HarbormasterBuildLog::initializeNewBuildLog($this) 258 258 ->setLogSource($log_source) 259 - ->setLogType($log_type); 260 - 261 - $log->start(); 259 + ->setLogType($log_type) 260 + ->openBuildLog(); 262 261 263 262 return $log; 264 263 }
+3 -6
src/applications/harbormaster/worker/HarbormasterTargetWorker.php
··· 90 90 $target->setDateCompleted(PhabricatorTime::getNow()); 91 91 $target->save(); 92 92 } catch (Exception $ex) { 93 - phlog($ex); 94 - 95 93 try { 96 - $log = $build->createLog($target, 'core', 'exception'); 97 - $start = $log->start(); 98 - $log->append((string)$ex); 99 - $log->finalize($start); 94 + $log = $target->newLog('core', 'exception') 95 + ->append($ex) 96 + ->closeBuildLog(); 100 97 } catch (Exception $log_ex) { 101 98 phlog($log_ex); 102 99 }