Page MenuHomePhabricator

D7745.id17508.diff
No OneTemporary

D7745.id17508.diff

Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ src/__phutil_library_map__.php
@@ -2366,6 +2366,7 @@
'SlowvoteRemarkupRule' => 'applications/slowvote/remarkup/SlowvoteRemarkupRule.php',
'UploadArtifactBuildStepImplementation' => 'applications/harbormaster/step/UploadArtifactBuildStepImplementation.php',
'VariableBuildStepImplementation' => 'applications/harbormaster/step/VariableBuildStepImplementation.php',
+ 'WaitForPreviousBuildStepImplementation' => 'applications/harbormaster/step/WaitForPreviousBuildStepImplementation.php',
),
'function' =>
array(
@@ -5056,5 +5057,6 @@
'SlowvoteRemarkupRule' => 'PhabricatorRemarkupRuleObject',
'UploadArtifactBuildStepImplementation' => 'VariableBuildStepImplementation',
'VariableBuildStepImplementation' => 'BuildStepImplementation',
+ 'WaitForPreviousBuildStepImplementation' => 'BuildStepImplementation',
),
));
Index: src/applications/harbormaster/controller/HarbormasterBuildViewController.php
===================================================================
--- src/applications/harbormaster/controller/HarbormasterBuildViewController.php
+++ src/applications/harbormaster/controller/HarbormasterBuildViewController.php
@@ -49,7 +49,10 @@
$targets = array();
foreach ($build_targets as $build_target) {
$header = id(new PHUIHeaderView())
- ->setHeader(pht('Build Target %d', $build_target->getID()))
+ ->setHeader(pht(
+ 'Build Target %d (%s)',
+ $build_target->getID(),
+ $build_target->getImplementation()->getName()))
->setUser($viewer);
$properties = new PHUIPropertyListView();
@@ -280,7 +283,7 @@
case HarbormasterBuild::STATUS_PENDING:
return pht('Pending');
case HarbormasterBuild::STATUS_WAITING:
- return pht('Waiting on Resource');
+ return pht('Waiting');
case HarbormasterBuild::STATUS_BUILDING:
return pht('Building');
case HarbormasterBuild::STATUS_PASSED:
Index: src/applications/harbormaster/controller/HarbormasterBuildableViewController.php
===================================================================
--- src/applications/harbormaster/controller/HarbormasterBuildableViewController.php
+++ src/applications/harbormaster/controller/HarbormasterBuildableViewController.php
@@ -52,8 +52,8 @@
$item->addAttribute(pht('Pending'));
break;
case HarbormasterBuild::STATUS_WAITING:
- $item->setBarColor('blue');
- $item->addAttribute(pht('Waiting on Resource'));
+ $item->setBarColor('violet');
+ $item->addAttribute(pht('Waiting'));
break;
case HarbormasterBuild::STATUS_BUILDING:
$item->setBarColor('yellow');
Index: src/applications/harbormaster/query/HarbormasterBuildQuery.php
===================================================================
--- src/applications/harbormaster/query/HarbormasterBuildQuery.php
+++ src/applications/harbormaster/query/HarbormasterBuildQuery.php
@@ -8,6 +8,7 @@
private $buildStatuses;
private $buildablePHIDs;
private $buildPlanPHIDs;
+ private $idLessThan;
public function withIDs(array $ids) {
$this->ids = $ids;
@@ -34,6 +35,11 @@
return $this;
}
+ public function withIDLessThan($id) {
+ $this->idLessThan = $id;
+ return $this;
+ }
+
protected function loadPage() {
$table = new HarbormasterBuild();
$conn_r = $table->establishConnection('r');
@@ -133,6 +139,15 @@
$this->buildPlanPHIDs);
}
+ // This is probably susceptable to the odd / even ID situation. The
+ // only way to fix this would be to add a sequence column to build table.
+ if ($this->idLessThan) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'id < %d',
+ $this->idLessThan);
+ }
+
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
Index: src/applications/harbormaster/step/BuildStepImplementation.php
===================================================================
--- src/applications/harbormaster/step/BuildStepImplementation.php
+++ src/applications/harbormaster/step/BuildStepImplementation.php
@@ -53,7 +53,7 @@
/**
* Validate the current settings of this build step.
*/
- public function validate() {
+ public function validateSettings() {
return true;
}
Index: src/applications/harbormaster/step/WaitForPreviousBuildStepImplementation.php
===================================================================
--- /dev/null
+++ src/applications/harbormaster/step/WaitForPreviousBuildStepImplementation.php
@@ -0,0 +1,76 @@
+<?php
+
+final class WaitForPreviousBuildStepImplementation
+ extends BuildStepImplementation {
+
+ public function getName() {
+ return pht('Wait for Previous Builds');
+ }
+
+ public function getGenericDescription() {
+ return pht(
+ 'Wait for previous builds of the same build plan to finish '.
+ 'before continuing.');
+ }
+
+ public function getDescription() {
+ return pht(
+ 'Wait for previous builds of the same build plan to finish '.
+ 'before continuing.');
+ }
+
+ public function execute(
+ HarbormasterBuild $build,
+ HarbormasterBuildTarget $build_target) {
+
+ // We are blocked until all previous builds finish.
+ $build->setBuildStatus(HarbormasterBuild::STATUS_WAITING);
+ $build->save();
+
+ // Block until all previous builds of the same build plan have
+ // finished.
+ $plan = $build->getBuildPlan();
+
+ $log = null;
+ $log_start = null;
+ $blockers = $this->getBlockingBuilds($plan, $build);
+ while (count($blockers) > 0) {
+ if ($build->checkForCancellation()) {
+ if ($log !== null) {
+ $log->finalize($log_start);
+ }
+ return;
+ }
+
+ if ($log === null) {
+ $log = $build->createLog($build_target, "waiting", "blockers");
+ $log_start = $log->start();
+ }
+
+ $ids = mpull($blockers, 'getID');
+ $log->append("Blocked by builds: ".implode(",", $ids)."\n");
+
+ sleep(1);
+ $blockers = $this->getBlockingBuilds($plan, $build);
+ }
+ if ($log !== null) {
+ $log->finalize($log_start);
+ }
+
+ // Move back into building status.
+ $build->setBuildStatus(HarbormasterBuild::STATUS_BUILDING);
+ $build->save();
+ }
+
+ private function getBlockingBuilds(
+ HarbormasterBuildPlan $plan,
+ HarbormasterBuild $source) {
+
+ return id(new HarbormasterBuildQuery())
+ ->setViewer(PhabricatorUser::getOmnipotentUser())
+ ->withBuildPlanPHIDs(array($plan->getPHID()))
+ ->withBuildStatuses(array(HarbormasterBuild::STATUS_BUILDING))
+ ->withIDLessThan($source->getID())
+ ->execute();
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Wed, Jun 12, 6:41 PM (1 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6286607
Default Alt Text
D7745.id17508.diff (6 KB)

Event Timeline