Skip to content

Commit cf09574

Browse files
author
epriestley
committed
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
1 parent 58aac5d commit cf09574

File tree

5 files changed

+42
-79
lines changed

5 files changed

+42
-79
lines changed

src/applications/harbormaster/step/HarbormasterWaitForPreviousBuildStepImplementation.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,7 @@ public function execute(
3131
// Block until all previous builds of the same build plan have
3232
// finished.
3333
$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-
4634
$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-
}
5235

5336
if ($blockers) {
5437
throw new PhabricatorWorkerYieldException(15);

src/applications/harbormaster/storage/build/HarbormasterBuild.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,6 @@ public function isAutobuild() {
234234
return ($this->getPlanAutoKey() !== null);
235235
}
236236

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-
254237
public function retrieveVariablesFromBuild() {
255238
$results = array(
256239
'buildable.diff' => null,

src/applications/harbormaster/storage/build/HarbormasterBuildLog.php

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

3-
final class HarbormasterBuildLog extends HarbormasterDAO
3+
final class HarbormasterBuildLog
4+
extends HarbormasterDAO
45
implements PhabricatorPolicyInterface {
56

67
protected $buildTargetPHID;
@@ -10,7 +11,6 @@ final class HarbormasterBuildLog extends HarbormasterDAO
1011
protected $live;
1112

1213
private $buildTarget = self::ATTACHABLE;
13-
private $start;
1414

1515
const CHUNK_BYTE_LIMIT = 102400;
1616

@@ -20,8 +20,8 @@ final class HarbormasterBuildLog extends HarbormasterDAO
2020
const ENCODING_TEXT = 'text';
2121

2222
public function __destruct() {
23-
if ($this->start) {
24-
$this->finalize($this->start);
23+
if ($this->getLive()) {
24+
$this->closeBuildLog();
2525
}
2626
}
2727

@@ -34,6 +34,35 @@ public static function initializeNewBuildLog(
3434
->setLive(0);
3535
}
3636

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+
65+
3766
protected function getConfiguration() {
3867
return array(
3968
self::CONFIG_AUX_PHID => true,
@@ -73,26 +102,13 @@ public function getName() {
73102
return pht('Build Log');
74103
}
75104

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-
90105
public function append($content) {
91106
if (!$this->getLive()) {
92-
throw new Exception(
93-
pht('Start logging before appending data to the log.'));
107+
throw new PhutilInvalidStateException('openBuildLog');
94108
}
95-
if (strlen($content) === 0) {
109+
110+
$content = (string)$content;
111+
if (!strlen($content)) {
96112
return;
97113
}
98114

@@ -152,21 +168,6 @@ public function append($content) {
152168
}
153169
}
154170

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-
170171
public function getLogText() {
171172
// TODO: This won't cope very well if we're pulling like a 700MB
172173
// log file out of the DB. We should probably implement some sort

src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,8 @@ public function newLog($log_source, $log_type) {
256256

257257
$log = HarbormasterBuildLog::initializeNewBuildLog($this)
258258
->setLogSource($log_source)
259-
->setLogType($log_type);
260-
261-
$log->start();
259+
->setLogType($log_type)
260+
->openBuildLog();
262261

263262
return $log;
264263
}

src/applications/harbormaster/worker/HarbormasterTargetWorker.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,10 @@ protected function doWork() {
9090
$target->setDateCompleted(PhabricatorTime::getNow());
9191
$target->save();
9292
} catch (Exception $ex) {
93-
phlog($ex);
94-
9593
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();
10097
} catch (Exception $log_ex) {
10198
phlog($log_ex);
10299
}

0 commit comments

Comments
 (0)